$url="/images/convert.gif"; //url of image you want to convert (you will have to make an image upload script if you want to get these from user's harddrives)
$from="gif"; //convert from: gif | png | jpeg
$to="png"; //convert to: gif | png | jpeg
//------------------------------------------------------
header("Content-Type: image/".$to);
@{"image".$to}({"imagecreatefrom".$from}($url));
| |
|
Welcome to KnowledgeSutra - Dear Guest | |
Convert Gif & Png To Jpeg
Started by Rojay, Aug 08 2005 07:07 AM
12 replies to this topic
#11
Posted 30 April 2008 - 03:52 PM
I know this is an old topic but nobody has given the easiest answer yet to this simple question. I believe GD library has some php functions for you to use to do this. Something like this should work:
#12
Posted 25 May 2010 - 05:58 PM
Rojay, on 08 August 2005 - 07:07 AM, said:
how can i convert gifs and pngs to jpeg using php ??
If you ended up here from google searching for this like I did, this may help:
useful php info
#13 Guest_rob1951_*
Posted 07 June 2011 - 10:25 PM
To convert png to jpg try this:
Get a file from a form input
do some stuff to separate off the extension then...
if($extension=="png")
{
$uploadedfile = $_FILES['file']['tmp_name'];
$src = imagecreatefrompng($uploadedfile);
imagejpeg($src, 'test.jpg');
}
similar if the input image is gif
or to convert e.g. jpg to gif use imagegif instead of imagejpeg
Get a file from a form input
do some stuff to separate off the extension then...
if($extension=="png")
{
$uploadedfile = $_FILES['file']['tmp_name'];
$src = imagecreatefrompng($uploadedfile);
imagejpeg($src, 'test.jpg');
}
similar if the input image is gif
or to convert e.g. jpg to gif use imagegif instead of imagejpeg
Reply to this topic

1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users














