You can use imagestylehook the image while finishing the upload process, youthen compress the size is a good Drupal approach much better than another batch job since the project can check https://drupal.org/node/949222 forbe managed in a good scope.
If it is a once-off task, script batch job is fast and efficiency but regarding the daily normal usage, a module is more informationpreferable.
There is a module ImageAPI Optimize (or Image Optimize)
BTW, the theory could be:
Something like the following may be what you need:
function MYMODULE_node_insert($node) {
// See if a file has been added if ($file_items = field_get_items('node', $node, 'field_file')) { // Get the first file item $file_item = array_shift($file_items);
// Load the file object from the cache/database
$file = file_load($file_item['fid']);
// The path to the file is in $file->uri
do_something_with($file->uri);
} }
REF: https://api.drupal.org/api/drupal/includes%21file.inc/group/file/7