PHP Classes
elePHPant
Icontem

PHP GIF Resizer: Resize images and animations based on the GIF89a

Recommend this page to a friend!
  Info   View files Example   View files View files (23)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog    
Last Updated Ratings Unique User Downloads Download Rankings
2015-08-13 (3 years ago) RSS 2.0 feedNot enough user ratingsTotal: 273 All time: 7,489 This week: 415Up
Version License PHP version Categories
gif-resizer 1.0.4GNU Lesser Genera...5.3PHP 5, Graphics, Video
Description Author

This package can resize images and animations based on the GIF89a.

It takes the path of a given GIF image or animation file and creates a resized version with a specified width, height or ratio.

The resized image is saved to another file with a given file name.

Name: Asbjorn Grandt <contact>
Classes: 10 packages by
Country: Denmark Denmark
Age: 47
All time rank: 1771 in Denmark Denmark
Week rank: 105 Up1 in Denmark Denmark Equal
Innovation award
Innovation award
Nominee: 4x

Details

Resize animated Gif files

This package aims to implement a proper resizing of gif files encompassing the GIF89a specification.

Introduction

Most, if not all other publicly available gif resize packages fails with optimized gif files, those where only parts of the file are updated in subsequent frames. See these as a background image, with sprites moving about. The resulting gif will retain its aspect ratio.

The package is a bit pedantic in its approach. It was made as much for me to learn what Gifs were and how they work, as it was to solve specific problem.

Usage

The package needs to write to a file, the reasons for not just return a string is twofold. One being memory usage, the other is that you really don't want to be dynamically resizing often used gif files every time they are used.

Import

Add this requirement to your composer.json file:

    "grandt/phpresizegif": ">=1.0.3"

Composer

If you already have Composer installed, skip this part.

Packagist, the main composer repository has a neat and very short guide.

Or you can look at the guide at the Composer site.

The easiest for first time users, is to have the composer installed in the same directory as your composer.json file, though there are better options.

Run this from the command line:

php -r "readfile('https://getcomposer.org/installer');" | php

This will check your PHP installation, and download the composer.phar, which is the composer binary. This file is not needed on the server though.

Once composer is installed you can create the composer.json file to import this package.

{
    "require": {
        "grandt/phpresizegif": ">=1.0.3"
    }
}

Followed by telling Composer to install the dependencies.

php composer.phar install

this will download and place all dependencies defined in your composer.json file in the vendor directory.

Finally, you include the autoload.php file in the new vendor directory.

<?php
    require 'vendor/autoload.php';
    .
    .
    .

Initialization

include "../vendor/autoload.php";
use grandt\ResizeGif\ResizeGif;

$srcFile = "[path to original gif file]";
$dstFile = "[path to resized file]";

ResizeGif::ResizeToWidth($srcFile, $dstFile, 100);

To make a 100 pixel wide thumbnail

ResizeGif::ResizeToWidth($srcFile, $dstFile, 100);

To make a 100 pixel high thumbnail

ResizeGif::ResizeToHeight($srcFile, $dstFile, 100);

To double the size of the gif.

ResizeGif::ResizeByRatio($srcFile, $dstFile, 2.0);

To half the size of the gif.

ResizeGif::ResizeByRatio($srcFile, $dstFile, 0.5);
  Files folder image Files  
File Role Description
Files folder imagesrc (1 directory)
Files folder imagetests (4 files, 1 directory)
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file README.md Doc. Auxiliary data
Accessible without login Plain text file REVISION.TXT Data Documentation

  Files folder image Files  /  src  
File Role Description
Files folder imageResizeGif (3 files, 3 directories)

  Files folder image Files  /  src  /  ResizeGif  
File Role Description
Files folder imageDebug (1 file)
Files folder imageFiles (3 files)
Files folder imageStructure (8 files)
  Plain text file CreateGif.php Class V1.0.2: Added: CreateGif. CreateGif is a simple Gif Animation creation script.
  Plain text file ExtractGif.php Class Gif frame extraction
  Plain text file ResizeGif.php Class Class source

  Files folder image Files  /  src  /  ResizeGif  /  Debug  
File Role Description
  Plain text file DebugGif.php Class Class source

  Files folder image Files  /  src  /  ResizeGif  /  Files  
File Role Description
  Plain text file DataHandler.php Class Class source
  Plain text file FileHandler.php Class Class source
  Plain text file ImageHandler.php Class Class source

  Files folder image Files  /  src  /  ResizeGif  /  Structure  
File Role Description
  Plain text file AbstractExtensionBlock.php Class Class source
  Plain text file ApplicationExtension.php Class Class source
  Plain text file CommentExtension.php Class Class source
  Plain text file GraphicControlExtension.php Class Class source
  Plain text file Header.php Class Class source
  Plain text file ImageDescriptor.php Class Class source
  Plain text file LogicalScreenDescriptor.php Class Class source
  Plain text file PlainTextExtension.php Class Class source

  Files folder image Files  /  tests  
File Role Description
Files folder imageresources (1 file)
  Accessible without login Plain text file CreateGif.Test1.php Example V1.0.2: Added: CreateGif. CreateGif is a simple Gif Animation creation script.
  Accessible without login Plain text file ExtractGif.Test1.php Example Gif frame extraction example
  Accessible without login Plain text file ResizeGif.Test1.php Example Example script
  Accessible without login Plain text file ResizeGif.Test2.php Example Example script

  Files folder image Files  /  tests  /  resources  
File Role Description
  Accessible without login Image file frame_diff_ir2t.gif Icon Example gif file.

 Version Control Unique User Downloads Download Rankings  
 100%
Total:273
This week:0
All time:7,489
This week:415Up