How to resize a GIF


Back to programming.


*kimaci    (2010-05-22)
How to resize a GIF

Hi all, here is a small script very useful that is able to resize a GIF while maintaining the transparency:

rename($_FILES['image']['tmp_name'], $image_path);

// chmod($image_path,0755);

list($photo_width,$photo_height) = getimagesize($image_path);
 
if ($img_size[2] == 1) $photo_resource = imagecreatefromgif($image_path);
elseif ($img_size[2] == 3) $photo_resource = imagecreatefrompng($image_path);
else $photo_resource = imagecreatefromjpeg($image_path);

$photo_resource_resized = imagecreatetruecolor($new_width, $new_height);

if ($img_size[2] == 1)
{
  $originaltransparentcolor = imagecolortransparent( $photo_resource );
  if ($originaltransparentcolor >= 0 && $originaltransparentcolor < imagecolorstotal($photo_resource))
{
  $transparentcolor = imagecolorsforindex( $photo_resource, $originaltransparentcolor );
  $newtransparentcolor = imagecolorallocate($photo_resource_resized, $transparentcolor['red'], $transparentcolor['green'],$transparentcolor['blue']);
  imagefill( $photo_resource_resized, 0, 0, $newtransparentcolor );
  imagecolortransparent( $photo_resource_resized, $newtransparentcolor );
}
}

imagecopyresampled($photo_resource_resized, $photo_resource, 0, 0, 0, 0, $new_width, $new_height, $photo_width, $photo_height);
 
if ($img_size[2] == 1) imagegif($photo_resource_resized,$image_path);
elseif ($img_size[2] == 3) imagepng($photo_resource_resized,$image_path);
else imagejpeg($photo_resource_resized,$image_path);



See also


ficgs
More websites

You must register to see these links, as this is a collaborative page, then you may change the order of the links by clicking the icons before the titles.



admin
Other websites

The following links might be less relevant, please change their ranks if you find them useful.


 Yahoo! Answers - Get answers, ask questions, find information
answers.yahoo > question/index%3Fqid%3D20080123080416AAFkmrg%2B
  1. Yahoo! does not evaluate or guarantee the accuracy of any Yahoo!
 Picasion - Create GIF animations online - Make an Animated GIF
picasion > resize image/&amp;sa=U&amp;ei= uRuUMuEIKGh0QWHgoHwCA&amp;

It stands for Graphics Interchange Format and, unlike jpg it is a...

 GIFs
ineedagif.tumblr

Sadly, after 20 minutes (or maybe even hours) of searching the...

 How to Resize Gif: 6 steps (with pictures) - wikiHow
wikihow > Resize Gif&amp;sa=U&amp;ei= uRuUMuEIKGh0QWHgoHwCA&amp;ved=

Create a Video Greeting Card With GoAnimate in YouTube...

 The Page or Image You Ask Not Available / Arad
uploadedit > to upload edit resize resample animated gif.htm%2B



Response  
 

Guest name   (option)     Register
Please sum : 4681 + eight  




Trackbacks : If you talked about this article in your blog or website, you may instantly get a backlink 
There's no trackback at the moment.