jpeg to gif conversion going wrong

images php coding issues or problems here.

Moderators: macek, egami, gesf

Post Reply
Raint
New php-forum User
New php-forum User
Posts: 6
Joined: Tue Mar 08, 2011 10:16 pm

Re: jpeg to gif conversion going wrong

Post by Raint » Wed Mar 09, 2011 2:56 am

gif is format with only 256 colors, so photo quality will allways decrease alot...



___________________________________________________________________________________
Try your PHP code instantly. http://www.freephptest.com

phmyway
New php-forum User
New php-forum User
Posts: 6
Joined: Mon Feb 28, 2011 11:45 pm

Re: jpeg to gif conversion going wrong

Post by phmyway » Thu Mar 10, 2011 12:45 am

I think I agree with Raint that the quality of gif is lower that jpeg. But you try the following coding if it works
<?php
//read all the attributes of the image first with this:
list($width, $height, $type, $attr) = getimagesize($ImageName);

//then
if ($type == 2) { //this is to mean if the format type is JPG
rename($ImageName, $newfilename);
} else {
if ($type == 1) { //that is to mean if the format type is GIF
$image_old = imagecreatefromgif($ImageName); //that is change GIF or gif formats to jpg
} elseif ($type == 3) {
$image_old = imagecreatefrompng($ImageName); //that is change PNG or png formats to jpg
}

//convert the image to gif
$image_gif = imagecreatetruecolor($width, $height);
imagecopyresampled($image_gif, $image_old, 0, 0, 0, 0, $width, $height, $width, $height);
imagegif($image_gif, $newfilename);
imagedestroy($image_old);
imagedestroy($image_gif);

}

//bobthebuilder: I hope the above function may keep the resolution intact.
//Bye for now and pls let me hear from you.
?>

Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests