Module | Pixels |
In: |
lib/pixels.rb
|
Ruby Pixels allows you to read and write RGB/RGBA pixel data stored in uncompressed, non-interleaved TGA (Targa) files.
Unlike some other libraries, Ruby Pixels reads and writes one row of pixels at a time, you can work with several large images at once without running out of memory.
Ruby Pixels needs no external libraries.
Ruby Pixels cannot read or write compressed, interleaved, or colour-mapped images. You may wish to use another tool (e.g. MiniMagick) to convert to and from other formats.
Ruby Pixels currently has no support for reading or writing individual pixels. You need to do it on a row-by-row basis.
# invert-image.rb - Invert the colour of an image. require 'pixels' input = Pixels.open_tga("mm/mm-01.tga") output = Pixels.create_tga("output.tga", input.spec) input.each_row_rgb do |in_row, y| out_row = [] for r, g, b in in_row out_row << [255-r, 255-g, 255-b] end output.put_row_rgb(y, out_row) end output.close input.close
VERSION | = | '0.0.1' |
Create a TGA file according to the given specification, and return an instance of one of TargaBase‘s children (one of Targa15, Targa16, Targa24, or Targa32), depending on the format specification.
file_or_path may be a pathname or a file-like object. If it is a pathname, it is opened for reading.
spec is a Hash containing the following keys:
Currently, this is always one of [15, 24].
Note: This only affects the TGA file‘s internal layout. get_row_rgb(0) always returns the uppermost row in Ruby Pixels. (default :UPPER_LEFT)