All of the content types on my site allow users to upload up to 10 images. Each file is around 2 to 6 mb in original size.

I don't want to add another layer of complexity to their posting experience by enforcing that they use photoshop or some other software to 'format for web.' before uploading (which would be the case if I set the max file size to, 512k, for example).

Instead, how can I do like other services where you can upload whatever size and then the backend takes care of formatting them to a much smaller size for storage as well as the be the original that image caching uses for its work?

I see two ways of handling it: write a module that understands when the file is saved and use PHP to reformat via its image functions, and then save that new file on the file system as well as be the source of any related image information needed in the database.

or, if the image data in the database is not dependent on the uploaded file size, etc, then why not just write an independed script to loop through all the images and reformat their sizes? Doesn't even have to be a module really.

Thoughts on the best way to do that?

  • or, maybe there is already a module for this? if so please share!
    – blue928
    Jul 27, 2012 at 3:44

2 Answers 2


hook the image while finishing the upload process, then compress the size is a good Drupal approach much better than another batch job since the project can be 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 preferable.

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

} }

REF: https://api.drupal.org/api/drupal/includes%21file.inc/group/file/7


Hi you can try this very helpful Module Original image with style


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.