1

I have a Drupal 7 site that allows users to upload pictures of themselves. While the pictures aren't using much space on the server's filesystem now, I am worried that if my membership grows substantially I will have to add more space to cover all the images.

Right now, I allow users to upload images up to 10 MB in size. I want to leave this limit high if possible because many of my users are not technically skilled and they do not know how to resize their images.

At the same time, the largest resolution that will be used on the site is 1024x1024. So, I have configured the core image field to automatically scale down the images to 1024x1024. This significantly reduces the file size.

Are there any other ways to automatically reduce the size of uploaded images? Please note that I am talking about the original files, not image styles.

  • Maybe I misunderstood the question: Are you looking for the setting Drupal 6 ImageCache had "flush preset(s)"? This thread discusses the topic. – texas-bronius Jul 30 '13 at 3:17
  • @texas-bronius No, I'm looking to re-size the actual image files, not to clear the image styles cache. – Patrick Kenny Jul 30 '13 at 4:46
1

A module like Max Image Size will resize the original images that have already been uploaded, you can specify a new maximum width and height.

2

Interesting question - this should be a standard option on community distributions to avoid the space issue you raised but you're right that the focus seems to be on image styles as a solution..

Two ways to handle this

  • More custom way would be to add a hook_form_alter to your form that would add a submit handler to resize the image file after uploaded to the correct size -- if you are able to do image styles than your server already has the image libraries needed to do this.

  • An easier way would be to use an uploader that can be configured to do this work for you on the upload. One example is the plupload module / widget which has a clientside resize option during the upload (also saving bandwidth)

    resize
    
    Enables plupload to resize the images to clientside to the 
    specified width, height and quality. Set this to an object with those
    parameters.
    
  • If I will set the "Maximum image resolution" on the image field - it will shrink the image on the client side, and only after that will upload it to my Drupal site? which mean save bandwidth like Plupload integration module? – EB84 Feb 15 '14 at 12:50
1

I love your question, because it's exactly what I am looking to do. In fact, I think it'd make a great module to:

  • Allow virtually any size/dimension images
  • Resize the stored Original behind the scenes to some web-reasonable maximums (even larger than reasonable but well below 2MB) and discard the uploaded bloat
  • Other image style / imagecache settings apply against the new original as normal

Then as a maintenance task, say, on activation of said module, the meat of the process runs and smashes down all originally uploaded biggies the way you (and I) both came here to find a way to do.

To answer specifically your original question, I think a mogrify op may be in order. It's part of ImageMagick (sic), like one of either:

mogrify -define jpeg:extent=567KB *.jpg
mogrify -geometry 1024 *.jpg

Here, I'm showing the -geometry switch constraining to 1024 px wide and whatever proportionate height. 1024 square would be 1024x1024.

Note, other examples on the web include a "-path" directive which didn't work for me, I presume because of an ImageMagick version difference.

  • Btw @patrickKenny, I might clarify that the mogrify command would be run in commandline against your sites/default/files/[whatever] folder(s) directly and would be performed as a one-time or periodic maintenance task. My module idea would incorporate the same command as a pre-save-original action. – texas-bronius Dec 13 '13 at 19:25
-1

you could hook in to "theme_image_style()" and do a check on every image for size every time it loads.

if I was doing it though, since it's just a one time thing, you may be better off doing a bootstrap and writing your own script to resize.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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