Convert GIF to JPG and JPG to GIF with PHP?

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
JAB Creations
DevNet Resident
Posts: 2341
Joined: Thu Jan 13, 2005 6:44 pm
Location: Sarasota Florida
Contact:

Convert GIF to JPG and JPG to GIF with PHP?

Post by JAB Creations »

I'd like to convert GIF and JPG image formats using PHP, what (if any) functions are available for me to do this? I've spotted jpeg2wbmp and png2wbmp but those don't seem to be what I want.
User avatar
it2051229
Forum Contributor
Posts: 312
Joined: Tue Dec 25, 2007 8:34 pm

Re: Convert GIF to JPG and JPG to GIF with PHP?

Post by it2051229 »

research on the GD library classes of php, for graphics actually.. but there are a lot of generic classes of PHP which was written by programmers long ago that does conversion, resizing, etc. etc... you can download them at http://www.phpclasses.org although you need to register, and after registration make use of there search box for searching what you need.
User avatar
JAB Creations
DevNet Resident
Posts: 2341
Joined: Thu Jan 13, 2005 6:44 pm
Location: Sarasota Florida
Contact:

Re: Convert GIF to JPG and JPG to GIF with PHP?

Post by JAB Creations »

I've been to that site numerous times in the past...not seeing anything I need right now...GIF converter, conversion, "JPG to GIF", etc on the Google search. Most of the things that came up on Google were in regards to image editing applications, not PHP.
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Re: Convert GIF to JPG and JPG to GIF with PHP?

Post by onion2k »

If you have GD installed..

Gif to Jpeg:

Code: Select all

$image = imagecreatefromgif("image.gif");
imagejpeg($image);
Jpeg to Gif:

Code: Select all

$image = imagecreatefromjpeg("image.jpg");
imagetruecolortopalette($image);
imagegif($image);
Don't expect fantastic results though. GIF and JPEG formats are designed for very different purposes, and an image in one format is never going to look very good in the other.
Post Reply