Author Topic: [MOD]GIF Resizer without loss of Animation  (Read 5891 times)

0 Members and 1 Guest are viewing this topic.

Offline sathishIPL

  • Jr. Member
  • **
  • Posts: 54
    • View Profile
[MOD]GIF Resizer without loss of Animation
« on: February 19, 2012, 07:39:03 AM »
Hi All,

The gif resizer class was not written by me.

It was taken from here
http://www.phpclasses.org/package/7353-PHP-Resize-animations-in-files-of-the-GIF-format.html.

I have just integrated into the 4images.

Goto Includes/image_utils.php

find the function resize_image_gd

function resize_image_gd($src$dest$quality$width$height$image_info) {
  global 
$convert_options;

  
$types = array(=> "gif"=> "jpeg"=> "png");
  if (
$convert_options['convert_gd2']) {
    
$thumb imagecreatetruecolor($width$height);
  }
  else {
    
$thumb imagecreate($width$height);
  }
  
$image_create_handle "imagecreatefrom".$types[$image_info[2]];
  if (
$image $image_create_handle($src)) {
    if (
$convert_options['convert_gd2']) {
      
imagecopyresampled($thumb$image0000$width$heightImageSX($image), ImageSY($image));
    }
    else {
      
imagecopyresized($thumb$image0000$width$heightImageSX($image), ImageSY($image));
    }

    if (
$image_info[2] == 3) {
      
$quality 9;
    }

    
$image_handle "image".$types[$image_info[2]];
    
$image_handle($thumb$dest$quality);
    
imagedestroy($image);
    
imagedestroy($thumb);
  }
  return (
file_exists($dest)) ? 0;
}


Replace with the below code


function resize_image_gd($src$dest$quality$width$height$image_info) {
  global 
$convert_options;

  
$types = array(=> "gif"=> "jpeg"=> "png");
  if(
$types[$image_info[2]]=="gif"){
	
//require_once "gifresizer.php";
	
//Including our class
	
require(
ROOT_PATH.'includes/gifresizer.php');
	
$gr = new gifresizer;
	
//New Instance Of GIFResizer
	
$gr->temp_dir THUMB_TEMP_PATH//Used for extracting GIF Animation Frames
	
$gr->resize($src,$dest,$width,$height); //Resizing the animation into a new file.
  
}
  else{
  if (
$convert_options['convert_gd2']) {
    
$thumb imagecreatetruecolor($width$height);
  }
  else {
    
$thumb imagecreate($width$height);
  }
  
  
$image_create_handle "imagecreatefrom".$types[$image_info[2]];
  if (
$image $image_create_handle($src)) {
    if (
$convert_options['convert_gd2']) {
      
imagecopyresampled($thumb$image0000$width$heightImageSX($image), ImageSY($image));
    }
    else {
      
imagecopyresized($thumb$image0000$width$heightImageSX($image), ImageSY($image));
    }

    if (
$image_info[2] == 3) {
      
$quality 9;
    }

    
$image_handle "image".$types[$image_info[2]];
    
$image_handle($thumb$dest$quality);
    
imagedestroy($image);
    
imagedestroy($thumb);
  }
  }
  return (
file_exists($dest)) ? 0;
}


and download the gifresizer.php

Upload into the yourdomain/includes/gifresizer.php

It will resize your Gif Images without loss of animations.

Br,
Satz


Rembrandt

  • Guest
Re: [MOD]GIF Resizer without loss of Animation
« Reply #1 on: February 19, 2012, 10:07:11 AM »
Hi!

Thank you for providing this Mod!
It works Perfekt.

mfg Andi