84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
|
# File 'lib/epdfs.rb', line 84
def jpeg_dimensions(image)
raise ArgumentError, "Not a JPEG" unless jpeg?(image)
image = image.dup
image.slice!(0, 2) while marker = image.slice!(0, 4)
m, c, l = marker.unpack('aan')
raise "Bad JPEG" unless m == "\xFF"
if ["\xC0", "\xC1", "\xC2", "\xC3", "\xC5", "\xC6", "\xC7", "\xC9", "\xCA", "\xCB", "\xCD", "\xCE", "\xCF"].include?(c)
dims = image.slice(0, 6)
bits_per_component, height, width, components = dims.unpack('CnnC')
break
end
image.slice!(0, l - 2)
end
[width, height, components, bits_per_component]
end
|