4images Forum & Community

4images Modifications / Modifikationen => Mods & Plugins (Releases & Support) => Topic started by: sathishIPL on February 19, 2012, 07:39:03 AM

Title: [MOD]GIF Resizer without loss of Animation
Post by: sathishIPL 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 (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(1 => "gif", 2 => "jpeg", 3 => "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, $image, 0, 0, 0, 0, $width, $height, ImageSX($image), ImageSY($image));
    }
    else {
      imagecopyresized($thumb, $image, 0, 0, 0, 0, $width, $height, ImageSX($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)) ? 1 : 0;
}


Replace with the below code


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

  $types = array(1 => "gif", 2 => "jpeg", 3 => "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, $image, 0, 0, 0, 0, $width, $height, ImageSX($image), ImageSY($image));
    }
    else {
      imagecopyresized($thumb, $image, 0, 0, 0, 0, $width, $height, ImageSX($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)) ? 1 : 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

Title: Re: [MOD]GIF Resizer without loss of Animation
Post by: Rembrandt on February 19, 2012, 10:07:11 AM
Hi!

Thank you for providing this Mod!
It works Perfekt.

mfg Andi