0

Question

Why is it that sometimes a transformed JPG is larger than its original when it is transformed using Craft image transforms even though in my general.php file I set upscaleImages to false?

Case details

I upload JPG images with a width of 2600px and run them through several image transforms, one of them transforming images to a width of 2600px as well. I do this just in case larger images are being uploaded. Since upscaleImages is set to false, I assumed that images that are already 2600px wide would be skipped, but they somehow still get duplicated into the folder with the other transforms. What's even worse: While the original JPG is 6.4mb, the transformed one is 7.2mb. A small difference, but this will add up quickly when uploading several hundred images.

For testing purposes i also uploaded images i manually cropped to 2599px. They were not upscaled to 2600px (which is correct since I set upscaleImages to false) but they still got duplicated to a larger file size.

I run Craft CMS 4.2.0.2 with ImageMagick.

1 Answer 1

2

The upscaleImages setting only cares about image resolution (pixel dimensions), not file size. If you set this to false, Craft will never create an image with larger dimensions than the base image. So if you upload a 2500px wide image, it won't upscale that to 2600px, even if you request that size in an image transform.

The file size, however, depends on the amount of image compression. The size of the JPG file you're uploading depends on the quality settings it has been exported with, as well as any optimizations you may have applied to it. To create a transform, Craft has to decompress the image, convert it and then save it as a compressed image again. During this step, any compression / optimization you may have applied to the original JPG is lost in the generated image transform. So if you have, for example, exported the JPG from Photoshop with a low quality setting (e.g. ~60) and then run it through ImageOptim, chances are that the generated transform will have a larger file size.

You can optimize the generated transforms in a couple of ways:

  • You can specify a quality setting between 0 and 100 as part of the transform. A lower setting will result in higher compression at the (potential) cost of image quality. If you don't specify a quality, Craft will use the defaultImageQuality general config setting. The default for this setting is 82, which is a bit higher than you will need for most normal photos.
  • You can also run image optimization tools as part of the image transformation process. ImageOptimize is a plugin that does this for you.

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.