When I started working with images in PHP, I learned images should be resized and resampled to reduce file size. I'm taking resizing
here to be reducing an image height and width without intentionally altering image quality and resampling
to be resizing and intentionally altering image quality with imageconvolution() function. When comparing a group of images of the same dimensions, one resampled with PHP, the other not, I noticed not-so-subtle differences in the file sizes. These are my findings for one set of images, and they were similar to the other sets:
Resampled and Resized Image:
Resized Image without Resampling:
Original Image:
The resampled image is 4.3KB
bigger than the non-resampled image. This difference is relatively small, but if the resampled image turns out to be greater than the non-resampled image, what then is the importance of resampling? Is this a rare occurrence? Does this only happen to jpeg
files? N/B: I worked with imagecreatefromjpeg
, imagecreatetruecolor
, imagecopyresampled
, and imageconvolution
(when resampling).
Changing the size of an image always requires resampling in some form or another. See the definition of resampling at Wikipedia: https://en.wikipedia.org/wiki/Image_scaling#Mathematical. The difference in the final file size is probably entirely due to the different scaling techniques producing visually different images, which compress differently by the final JPEG algorithm. E.g. the larger file contains more details or graininess, which doesn't compress as well. You will have to choose which resizing algorithm and compression format you prefer and balance visual quality vs. file size of the end result.