GD library version?

software development


I have a small PHP script that I use as a generic scaler for thumbnails.

On my personal server, I believe I had GD library v1.4 and the thumbnails were fine.

Since hosting here, with the GD library v2.0, the color pallet on the thumbnail images is a wreck.

The lines I use for the scaling are:


Does the newer library require anything else to fix the colors?

Or is there a way to get PHP to use the older library on my account without needing to compile my own copy of PHP?




Have you read this note in the PHP manual?

[quote]Note: There is a problem due to palette image limitations (255+1 colors). Resampling or filtering an image commonly needs more colors than 255, a kind of approximation is used to calculate the new resampled pixel and its color. With a palette image we try to allocate a new color, if that failed, we choose the closest (in theory) computed color. This is not always the closest visual color. That may produce a weird result, like blank (or visually blank) images. To skip this problem, please use a truecolor image as a destination image, such as one created by imagecreatetruecolor().
Also, when you are using GD 2 you get much better quality from imagecopyresampled() than imagecopyresized().

[color=#000000]DreamHost Promo Code[/color]: [color=#CC0000]Save $50[/color] with the promo code DREAMTEAM


Thanks for the reply.

When I wrote my little generic rescaler, I only had access to GD lib v1.6 (I just rechecked the old server spec) and the imagecreatetruecolor() function is a GD lib v2.0 function.

A one-line edit did wonders for the output. Thanks for pointing me at the right function.



Did you also change to imagecopyresampled()? Another GD 2.0 function, which makes a hugh difference.

[color=#000000]DreamHost Promo Code[/color]: [color=#CC0000]Save $50[/color] with the promo code DREAMTEAM


Actually, I hadn’t made the change to ‘resampled’ from ‘resized.’

I found the output of ‘resized’ was quite good. When I replaced it with ‘resampled’ (a few minutes ago), I found no noticeable difference (at least with the images I was using as source).

Thanks, again for the help. I had written off GD 2.0 as useless for my application until you pointed out the different ‘imagecreate’ call.