Link to home
Start Free TrialLog in
Avatar of sigmatec_pk
sigmatec_pkFlag for Pakistan

asked on

How to create thumbnail of a transparent GIf in PHP?

Hi,

I want to create thumbnails of transparent gif images and want to keep it transparent aswell.
Can you please how can this be done without loosing image quality?

Thanks
Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

Simply put, it cannot be done without losing image quality.  If you want to post some examples of the images, I may be able to help with some of it.
If you will post some examples of the images, I will try to get you an answer.  I asked for that, but never saw any response.  Surely you have SOME test images for your project?!  Please post those images, and tell us the dimensions you want to use for the thumbnails.

Also, understand that an image that is large has more image information than an image that is small, and so when you say "without losing image quality" you are defining into existence a condition that is physically impossible.  That said, there may be solutions that will work for you, but we cannot help you unless you respond to our requests.

Thanks and regards, ~Ray
Avatar of sigmatec_pk

ASKER

You can use any transparent gif images. Search google images and you will get many.
Please upload an example image that you want us to use.  It's not up to us to guess your requirements!  Thanks.
These are the two sample gif images.
 User generated image User generated image
ASKER CERTIFIED SOLUTION
Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks for your reply. I'll try that and will update your soon.
Thanks for your reply Ray_Paseur.
It works very fine but there is only one issue. I need thumbnail in gif format, while you are making png thumb.

So I change
imagePNG($dst, 'RAY_temp_png.png', 9, PNG_ALL_FILTERS);
to
imagegif($dst, 'thumb,gif');

But that reduces quality of thumbnail.
Can you suggest some alternate to this?
Yes, I can suggest an alternative.  GIF is ancient history, and it's the wrong tool for the job.  Forget about it and use PNG thumbnails.  Here is why:  

GIF was considered a state-of-the-art technology for 1991, when (1) a high-speed internet connection was about 14KB/second and (2) computer monitors could display 256 colors and (3) you had to squeeze every bit of information out of graphics to avoid slow page loads.  GIF made sense in the earliest days of the internet.  GIF achieved its compression in part by using a palette of only 256 colors.  As you have observed in your tests, the color limitation makes the GIF format unsuitable for reproducing photographs or images with continuous color.
http://en.wikipedia.org/wiki/Graphics_Interchange_Format 

PNG became an international standard in 2003.  Today, the average internet connection speed is measured in megabytes instead of kilobytes.  Computer monitors display 16 million colors, not 256.  And the PNG standard is the open-source, state-of-the-art lossless compression technique for graphics and images.  
http://www.libpng.org/pub/png/

Times have changed.  GIF, and to some extent, JPG are out-of-date compression formats that guarantee inferior images.
Thanks for your assistance.
Thanks for the points.  It's a great question!