Page 1 of 1
resize image of type gif nake it black
Posted: Sat Jun 10, 2006 10:18 am
by pelegk1
when i resize a gif i recive a black image
why is that?
this is the code:
Code: Select all
header('Content-type: image/gif');
$thumb = ImageCreateTrueColor( $new_w, $new_h );
$source = imagecreatefromgif($input_file);
imagecopyresampled($thumb, $source, 0, 0, 0, 0, $new_w, $new_h, $width, $height);
imagegif($thumb, $new_name . '.gif',100);
thnaks in advance
peleg
Posted: Sat Jun 10, 2006 10:38 am
by bokehman
.gif are palette images so you should use
imagecreate() and not
imagecreatetruecolor(). If you are concerned about transparancy you will need to allocate the transparancy colour of the source to your drawing slate before copying it. Something like the following should cover most eventualities:
Code: Select all
function resize_gif($source, $destination = null, $longside = 150)
{
$w = $h = $longside;
$source = imagecreatefromgif($source);
if(($x = imagesx($source)) < ($y = imagesy($source)))
{
$w = round(($h / $y) * $x);
}
else
{
$h = round(($w / $x) * $y);
}
$slate = @imagecreate($w, $h) or die('Invalid thumbnail dimmensions');
if(false !== ($trans = @imagecolorsforindex($source, imagecolortransparent($source))))
{
$trans = ImageColorAllocate($slate, $trans['red'], $trans['green'], $trans['blue']);
imagefill($slate, 0, 0, $trans);
imagecolortransparent($slate, $trans);
}
imagecopyresampled($slate, $source, 0, 0, 0, 0, $w, $h, $x, $y);
$destination or header('Content-Type: image/gif');
$destination ? imagegif($slate, $destination) : imagegif($slate);
imagedestroy($source);
imagedestroy($slate);
$destination or die;
}
and what if the gif is animgif
Posted: Mon Jun 12, 2006 12:50 am
by pelegk2
will it work too?
Re: and what if the gif is animgif
Posted: Mon Jun 12, 2006 3:41 am
by bokehman
pelegk2 wrote:will it work too?
At present PHP has no built in support for animated gifs although there are hacks available.
what do u mean by :
Posted: Mon Jun 12, 2006 3:48 am
by pelegk2
although there are hacks available
Posted: Mon Jun 12, 2006 4:11 am
by bokehman
Like
this one for example but of course you would need to be in control of the server to install such a thing.