png (and gif?) to jpeg thumbnail

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
Skara
Forum Regular
Posts: 703
Joined: Sat Mar 12, 2005 7:13 pm
Location: US

png (and gif?) to jpeg thumbnail

Post by Skara »

First, is there an easy way to convert a png to a jpeg?
I don't want the original as such, I just want to make a thumbnail for it.

Second, I know that gifs are copyrighted, but frankly I don't care. :P Is there a way to get a thumbnail from these too?
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

Post by Burrito »

I haven't tried it, but seems like you could use imagecreatefrom%whatevertype%() and then use imageJPEG() to generate the image in a jpg format:

Code: Select all

$img = imagecreatefromgif("yourpath/yourimage.gif");
$width=imagesx($img);$height=imagesy($img); 
$thumb_Width=100;
$thumb_Height=75;
$scale = min($thumb_Width/$width, $thumb_Height/$height); 
$new_width=floor($scale*$width);
$new_height=floor($scale*$height); 
$tmp_img=imagecreatetruecolor($new_width,$new_height); 
imagecopyresampled($tmp_img,$img,0,0,0,0,$new_width,$new_height,$width,$height); 
imagedestroy($img); 
imageJPEG($tmp_img, "yourpath/yourimage.jpg");
User avatar
anjanesh
DevNet Resident
Posts: 1679
Joined: Sat Dec 06, 2003 9:52 pm
Location: Mumbai, India

Post by anjanesh »

Since PHP 4.3.9 (or 4.3.10 ?) gif support was included (since that version of bundled GD) - so I guess copyright issues wont come into place now.

1. imagecreatefrompng

2. imagegif
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

Post by Burrito »

you piqued my interest so I just tested it and it worked...
Roja
Tutorials Group
Posts: 2692
Joined: Sun Jan 04, 2004 10:30 pm

Re: png (and gif?) to jpeg thumbnail

Post by Roja »

Skara wrote: Second, I know that gifs are copyrighted, but frankly I don't care. :P Is there a way to get a thumbnail from these too?
Since the original question was answered, I wanted to throw in a quick correction here..

You meant they were patented, not copyrighted.

And until last year, when the patents expired, you would very much care if unisys came to you and told you to pay thousands for your use on "tiny-website.com", which is exactly what they did to several sites and companies.

Thankfully, that patent expired. Know the risks, and steer clear. :)

Knowledge is power!
User avatar
Skara
Forum Regular
Posts: 703
Joined: Sat Mar 12, 2005 7:13 pm
Location: US

Post by Skara »

haha, guess it's time to update then. :P Still on 4.3.4
Post Reply