maxim / smart_resize_image

(Written in 2007-08) PHP function for image resizing that does what you think it should, the right way.
77 stars 107 forks source link

compression needs to be improved #7

Open akehat opened 9 years ago

akehat commented 9 years ago

All in all, it's a very handy script.

My issue is - I'm using it not only to cut to size, but also to save on bandwidth. I ran the function on several images for several preset sizes. In some cases, the output is the same dimension as the original, but the output size was x3 - x4 the size. (e.g. - real example: original 59kb; output 198kb . See attachments below.)

The compression needs to be improved.

Thanks!

original: profile_1

resized: profile_1_225x225

clarkmu commented 7 years ago

The functions near the end of the script , imagejpeg and imagepng , also accept a third parameter for quality. Imagejpeg defaults to 75%, where you can set it to 100. imagepng is on a scale of 0-9 where 0 is no compression.

example on line 86:

switch ( $info[2] ) { case IMAGETYPE_GIF: imagegif($image_resized, $output); break; case IMAGETYPE_JPEG: imagejpeg($image_resized, $output, 100); break; case IMAGETYPE_PNG: imagepng($image_resized, $output, 0); break; default: return false; }

akehat commented 7 years ago

Thanks... though I totally forgot on which site I used this... :-)