I have a set of biography images in the site I'm working on, and I have an image style that will enforce the correct size for these. Of course I'd rather not have them resized if they don't need it, so I'm wondering if the resize & crop effect will be skipped if the image is already the perfect size.

In other words, if the image is 130 x 170, and the effect of the image style would be to resize & crop it to make it 130 x 170, will the Image module be clever enough to skip that effect and leave it alone (so as not to degrade quality)?

If it will process the image anyway, then obviously I'll want to simply display the original image. It would be very useful if the module were clever enough to know when not to run, so the image style could be there as a failsafe in case some future content editor is too lazy to crop the images beforehand.

1 Answer 1


It is all up to the PHP toolkit used to manipulate images. The code that is executed from the image effect is the following one. (See image_scale_and_crop_effect().)

function image_scale_and_crop(stdClass $image, $width, $height) {
  $scale = max($width / $image->info['width'], $height / $image->info['height']);
  $x = ($image->info['width'] * $scale - $width) / 2;
  $y = ($image->info['height'] * $scale - $height) / 2;

  if (image_resize($image, $image->info['width'] * $scale, $image->info['height'] * $scale)) {
    return image_crop($image, $x, $y, $width, $height);
  return FALSE;

The IF-statement is only used because image_resize() can return FALSE if the PHP image toolkit doesn't support the operation being executed on the image. The function called from image_size() (image_toolkit_invoke()) is generic, and it doesn't make assumptions about the operations currently enabled from the selected image toolkit.

  • Yes you're right. I realized there was a way I could test this: I set my JPEG quality down to 5%, and worked around the bugs with image styles by adding then removing an effect, then viewed the results: terrible quality, confirming the images were all processed even though they didn't need to be. It would be really nice if the Image module provided a way to say "only run this effect IF the size is not already x,y"..... so I guess it's time to make a feature request...
    – iconoclast
    Dec 12, 2012 at 17:20

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.