Giter Site home page Giter Site logo

animated-gif-shrinker's Introduction

Animated GIF Shrinker

A perl tool to help convert an animated GIF into a new image suitable for use as a Slack chat emoji using ImageMagick

Dependencies

Basic Usage

usage: ags -i <input> [-o <output>] [-w <width>] [-f <fps>] [--from <from-frame>] [--to <to-frame>] [-c <bounds>]
    --input        path to .gif for processing
    -i             

    --output       path to output new gif (default: <input>_output.gif)
    -o             

    --use-every    use every nth frame (default: 2)
    -u             

    --width        new width for image (default: input width)
    -w             

    --height       new height for image (default: scaled based on --width)
    -h             

    --fps          set the output frame rate (default: 10)
    -f             

    --from         first frame to use

    --to           last frame to use

    --crop          WxH+X+Y from X,Y grabbing WxH
    -c             

Example

Let's say we have this great GIF of Andre the Giant declining his opponents' offers to suplex him.

Andre Says No

This weighs in at ~2MB and is 255 pixels wide.

Slack restricts custom image emoji to <= 64KB and <= 128 pixels width.

Let's start with the default behavior of dropping every other frame and we'll resize to the maximum supported width in Slack (128px).

$ ags --input andre.gif --width 128

 * Getting stats for andre.gif
 * Extracting frames...
 * Then using every 2nd frame
 * Resizing frames to 128x?...
 * Assembling new animated GIF...
 * Getting stats for andre_output.gif
 * Cleaning up work files...
 * Done!

 Input:
   * andre.gif
   * 2.0MB
   * 255x191
   * 107 frames

 Output:
   * andre_output.gif
   * 539.3KB
   * 128x96
   * 53 frames

 Delta:
   * 1.5MB smaller
   * 72% smaller

Almost a 75% reduction, but we're still too big in terms of file size. Let's try resizing some more. When used as responses to messages on Slack, emoji appear smaller than the maximum size.

$ ags --input andre.gif --width 64

 * Getting stats for andre.gif
 * Extracting frames...
 * Then using every 2nd frame
 * Resizing frames to 64x?...
 * Assembling new animated GIF...
 * Getting stats for andre_output.gif
 * Cleaning up work files...
 * Done!

 Input:
   * andre.gif
   * 2.0MB
   * 255x191
   * 107 frames

 Output:
   * andre_output.gif
   * 185.7KB
   * 64x48
   * 53 frames

 Delta:
   * 1.8MB smaller
   * 90% smaller

Great! We made it 90% smaller, but we've still got too large a file for Slack. In the GIF there's several shots spliced together, so let's focus and get the best Andre reaction (I opened the GIF in The GIMP to preview the frames. You can also just experiment based on the reported frame count):

$ ags --input andre.gif --width 64 --from 39 --to 67

 * Getting stats for andre.gif
 * Extracting frames...
 * Then grabbing frames 39 to 67 of input's 1 to 107...
 * Then using every 2nd frame
 * Resizing frames to 64x?...
 * Assembling new animated GIF...
 * Getting stats for andre_output.gif
 * Cleaning up work files...
 * Done!

 Input:
   * andre.gif
   * 2.0MB
   * 255x191
   * 107 frames

 Output:
   * andre_output.gif
   * 54.7KB
   * 64x48
   * 14 frames

 Delta:
   * 1.9MB smaller
   * 97% smaller

Andre Says No

Excellent! By cutting out extra frames and focusing on the best action, we're able to squeeze another 7% out and get our file size down to well under the 64KB maximum Slack imposes, but now the clip looks too slow.

One more tweak to the frame rate and we should have this nailed...

$ ags --input andre.gif --width 64 --from 39 --to 67 --fps 8

 * Getting stats for andre.gif
 * Extracting frames...
 * Then grabbing frames 39 to 67 of input's 1 to 107...
 * Then using every 2nd frame
 * Resizing frames to 64x?...
 * Assembling new animated GIF...
 * Getting stats for andre_output.gif
 * Cleaning up work files...
 * Done!

 Input:
   * andre.gif
   * 2.0MB
   * 255x191
   * 107 frames

 Output:
   * andre_output.gif
   * 54.7KB
   * 64x48
   * 14 frames

 Delta:
   * 1.9MB smaller
   * 97% smaller

Andre Says No

Awesome, this is exactly what we need!

Andre No Emoji Slack

animated-gif-shrinker's People

Contributors

theraccoonbear avatar

Stargazers

Ryan Patrick Kyle avatar Josh Thomas avatar  avatar

Watchers

 avatar 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.