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
][4])
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
- Fork it.
- Create a branch (
git checkout -b 20101220-my-change
). - Commit your changes (
git commit -am "Added something"
). - Push to the branch (
git push origin 20101220-my-change
). - Create an Issue with a link to your branch.
- Enjoy a refreshing Orange Juice and wait.
Copyright
This gem was originaly developed by [Martin Kozák][https://github.com/martinkozak/optipng]. But original gem is broken, so this is the rebirth of it.
Copyright © 2015 Artyom Fedenko. See LICENSE.txt
for
further details.