Giter Club home page Giter Club logo

optipng's Introduction

Optipng

Optipng provides Ruby interface to the optipng tool. Some examples follow: (for details, see module documentation)

require "optipng"

Optipng.available?        # will return true (or false)

Optipng.optimize(["foo.png", "empty.png", "nonexist.png"], { :level => 5 })

# will run 'optipng -o 5 foo.png bar.png empty.png'
# and then will return for example: 
#   '#<struct Optipng::Result succeed={"foo.png => -22.1}}, errors=[["empty.png", "Unrecognized image file format"], ["nonexist.png", "Can't open the input file"]]>

It can be also run asynchronously by non-blocking way (with eventmachine) simply by giving block with one argument to #optimize. See documentation.

Call Result

Result contains members :success and :errors. Sucess member contains hash of successfully optimized files with ratio as value. Zero or positive percent ratio means the same as file has been skipped so already optimized. It's negative number against the number reported by optipng so it means new size against the old size.

Errors contains array with pairs where first member of the pair is filename and second the message. First one can be null if message isn't strictly associated with concrete file. (But fortunately usually it is.)

Contributing

  1. Fork it.
  2. Create a branch (git checkout -b 20101220-my-change).
  3. Commit your changes (git commit -am "Added something").
  4. Push to the branch (git push origin 20101220-my-change).
  5. Create an Issue with a link to your branch.
  6. Enjoy a refreshing Diet Coke and wait.

Copyright

Copyright © 2011 Martin Kozák. See LICENSE.txt for further details.

optipng's People

Contributors

martinpoljak avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

optipng's Issues

Optipng.available? fails on OS X

whereis: illegal option -- b
usage: whereis program [...]
/Users/betelgeuse/.rvm/gems/ruby-1.9.3-p125/gems/unix-whereis-0.1.1/lib/unix/whereis.rb:88:in `file?': undefined method `split' for nil:NilClass (NoMethodError)
    from /Users/betelgeuse/.rvm/gems/ruby-1.9.3-p125/gems/unix-whereis-0.1.1/lib/unix/whereis.rb:168:in `available?'
    from /Users/betelgeuse/.rvm/gems/ruby-1.9.3-p125/gems/optipng-0.2.1/lib/optipng.rb:43:in `available?'

This is on OS X 10.6.

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.