Code Monkey home page Code Monkey logo

phpresizegif's Introduction

Resize animated Gif files

Forked from grandt/phpresizegif v1.0.3

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

Fixed

Php 7.1 tempnam error notice issue

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:

    "simplylouis/phpresizegif": ">=1.0.4"

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);

phpresizegif's People

Contributors

grandt avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.