Module: Axon
- Defined in:
- lib/axon.rb,
lib/axon/fit.rb,
lib/axon/cropper.rb,
lib/axon/scalers.rb,
lib/axon/generators.rb,
lib/axon/alpha_stripper.rb,
ext/axon/interpolation.c,
ext/axon/jpeg.c,
ext/axon/png.c
Defined Under Namespace
Modules: Interpolation, JPEG, PNG Classes: AlphaStripper, BilinearScaler, Cropper, Fit, Image, NearestNeighborScaler, Noise, Solid
Constant Summary collapse
- VERSION =
'0.2.0'
Class Method Summary collapse
-
.jpeg(thing, *args) ⇒ Object
:call-seq: Axon.jpeg(thing [, markers]) -> image.
-
.jpeg_file(path, *args) ⇒ Object
:call-seq: Axon.jpeg_file(path [, markers], &block) -> block_result.
-
.png(thing) ⇒ Object
:call-seq: Axon.png(thing) -> image.
-
.png_file(path, *args) ⇒ Object
:call-seq: Axon.png_file(path, &block) -> block_result.
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
37 38 39 40 41 |
# File 'lib/axon.rb', line 37 def self.jpeg(thing, *args) thing = StringIO.new(thing) unless thing.respond_to?(:read) reader = JPEG::Reader.new(thing, *args) Image.new(reader) end |
.jpeg_file(path, *args) ⇒ Object
:call-seq:
Axon.jpeg_file(path [, markers], &block) -> block_result
Opens the file located at path and reads it as a compressed JPEG image.
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.
This method returns the result of the block.
Axon.jpeg_file("image.jpg", [:APP2]) do |image|
image.png_file("image.png") # saves "image.jpg" to "image.png"
end
62 63 64 65 66 |
# File 'lib/axon.rb', line 62 def self.jpeg_file(path, *args) File.open(path, 'rb') do |f| yield jpeg(f, *args) end 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
80 81 82 83 84 |
# File 'lib/axon.rb', line 80 def self.png(thing) thing = StringIO.new(thing) unless thing.respond_to?(:read) reader = PNG::Reader.new(thing) Image.new(reader) end |
.png_file(path, *args) ⇒ Object
:call-seq:
Axon.png_file(path, &block) -> block_result
Opens the file located at path and reads it as a compressed PNG image.
This method returns the result of the block.
Axon.png_file("image.png") do |image|
image.jpeg_file("image.jpg") # saves "image.png" to "image.jpeg"
end
97 98 99 100 101 |
# File 'lib/axon.rb', line 97 def self.png_file(path, *args) File.open(path, 'rb') do |f| yield png(f, *args) end end |