Module: Oil
Defined Under Namespace
Classes: JPEGReader, PNGReader
Constant Summary
collapse
- VERSION =
"0.1.3"
Class Method Summary
collapse
Class Method Details
.new(io, box_width, box_height) ⇒ Object
17
18
19
20
21
22
23
24
25
26
|
# File 'lib/oil.rb', line 17
def self.new(io, box_width, box_height)
case sniff_signature(io)
when :JPEG
return new_jpeg_reader(io, box_width, box_height)
when :PNG
return new_png_reader(io, box_width, box_height)
else
raise "Unknown image file format."
end
end
|
.sniff_signature(io) ⇒ Object
4
5
6
7
8
9
10
11
12
13
14
15
|
# File 'lib/oil.rb', line 4
def self.sniff_signature(io)
a = io.getc
b = io.getc
io.ungetc(b)
io.ungetc(a)
if (a == "\xFF".b && b == "\xD8".b)
return :JPEG
elsif (a == "\x89".b && b == "P".b)
return :PNG
end
end
|