axon

github.com/ender672/axon

DESCRIPTION:

axon reads, manipulates, and writes images.

axon depends only on libjpeg and libpng.

axon never stores an entire image in memory. All images and operations are streamed. This keeps memory requirements and latency low.

FEATURES:

  • Read and Write JPEG and PNG images.

  • Scale images using bilinear or nearest-neighbor interpolation.

  • Crop images and image regions.

  • Scale images to fit into a box while preserving aspect ratio.

SYNOPSIS:

# Short, chained example. Reads a JPEG from io_in and writes scaled png to
# io_out.
Axon.jpeg(io_in).fit(100, 100).png(io_out)

# Longer example, reads the JPEG header, looks at properties and header
# values, sets decompression options, scales the image, sets compression
# options, and writes a JPEG.
reader = Axon::JPEG::Reader(io, [:APP2])

puts reader.width  #=> Integer
puts reader.height #=> Integer
puts reader[:APP2] #=> Array of Strings
reader.scale_denom = 4 # Image will be scaled by 1/4 on read

fitted = Axon::Fit.new(reader, 100, 100) # Fits image in a 100x100 box
JPEG.write(fitted, io, :quality => 88)

BASIC API:

All image objects are expected to respond to the following methods:

* Image#height
  Output height of the image.
* Image#width
  Output width of the image.
* Image#color_model
  Can be :GRAYSCALE or :RGB
* Image#components
  RGB image with alpha has 4 components.
  RGB image has 3 components.
  Grayscale image with alpha has 2 components.
  Grayscale image has 1 component.
* Image#gets
  Returns the next line in the image as a binary ruby string.
* Image#lineno
  The line number of the next line that will be returned, starting at 0.

A Reader object has the same methods as an Image object, with added methods that are specific to the decoding of the image format.

REQUIREMENTS:

IJG JPEG Library Version 6b or later. pnglib version 1.2.x or later.

INSTALL:

gem install axon

LICENSE:

(The MIT License)

Copyright © 2011

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the ‘Software’), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED ‘AS IS’, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.