Module: Axon
- Defined in:
- lib/axon.rb,
lib/axon/fit.rb,
lib/axon/cropper.rb,
lib/axon/scalers.rb,
lib/axon/generators.rb,
ext/axon/interpolation.c,
ext/axon/jpeg.c,
ext/axon/png.c
Defined Under Namespace
Modules: Interpolation, JPEG, PNG Classes: BilinearScaler, Cropper, Fit, Image, NearestNeighborScaler, Noise, Solid
Constant Summary collapse
- VERSION =
'0.1.0'
Class Method Summary collapse
-
.jpeg(thing, *args) ⇒ Object
:call-seq: Axon.jpeg(thing [, markers]) -> image.
-
.png(thing) ⇒ Object
:call-seq: Axon.png(thing) -> image.
Class Method Details
.jpeg(thing, *args) ⇒ Object
:call-seq:
Axon.jpeg(thing [, markers]) -> image
Reads a compressed JPEG image from thing
. thing
can be an IO object or a string of JPEG data.
markers
should be an array of valid JPEG header marker symbols. Valid symbols are :APP0 through :APP15 and :COM.
If performance is important and you don’t care about any markers, you can avaoid reading any header markers by supplying an empty array for markers
.
When markers
is not given, all known JPEG markers will be read.
io_in = File.open("image.jpg", "r")
image = Axon.jpeg(io_in) # Read JPEG from a StringIO
jpeg_data = IO.read("image.jpg")
image_2 = Axon.jpeg(jpeg_data) # Read JPEG from image data
io_in = File.open("image.jpg", "r")
image_3 = Axon.jpeg(io_in, [:APP2]) # Only reads the APP2 marker
35 36 37 38 39 |
# File 'lib/axon.rb', line 35 def self.jpeg(thing, *args) thing = StringIO.new(thing) unless thing.respond_to?(:read) reader = JPEG::Reader.new(thing, *args) Image.new(reader) end |
.png(thing) ⇒ Object
:call-seq:
Axon.png(thing) -> image
Reads a compressed PNG image from thing
. thing
can be an IO object, the path to a PNG image, or binary PNG data.
io_in = File.open("image.png", "r")
image = Axon.png(io_in) # Read PNG from a StringIO
png_data = IO.read("image.png")
image_2 = Axon.png(png_data) # Read PNG from image data
53 54 55 56 57 |
# File 'lib/axon.rb', line 53 def self.png(thing) thing = StringIO.new(thing) unless thing.respond_to?(:read) reader = PNG::Reader.new(thing) Image.new(reader) end |