Class: Cul::Image::Properties::Jpeg
- Defined in:
- lib/cul_image_props/image/properties/types.rb
Constant Summary
Constants inherited from Base
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
-
#initialize(srcfile = nil) ⇒ Jpeg
constructor
A new instance of Jpeg.
Methods inherited from Base
#[], #add_dt_prop, #extent=, #format=, #hex_inspect, #length=, #ord_value, #sampling_unit=, #width=, #x_sampling_freq=, #y_sampling_freq=
Constructor Details
#initialize(srcfile = nil) ⇒ Jpeg
Returns a new instance of Jpeg.
141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 |
# File 'lib/cul_image_props/image/properties/types.rb', line 141 def initialize(srcfile=nil) super header_bytes = @src.read(2) unless header_bytes[0...2].unpack('C*') == Cul::Image::Magic::JPEG raise "Source file is not a jpeg: #{hex_inspect(header_bytes[0...2])}" end xpix = 0 ypix = 0 while (!@src.eof?) if 0xff == ord_value(@src.read(1)) mrkr = [0xff, ord_value(@src.read(1))] blen = @src.read(2).unpack('n')[0] if Cul::Image::Magic::JFM_BYTES.include? mrkr # SOFn, Start of frame for scans @src.read(1) #skip bits per sample self.length= @src.read(2).unpack('n')[0] self.width= @src.read(2).unpack('n')[0] @src.seek(0, IO::SEEK_END) else @src.seek(blen - 2, IO::SEEK_CUR) end else @src.seek(0, IO::SEEK_END) end end @src.rewind = Cul::Image::Properties::Exif.process_file(@src) if .include? 'Image ImageWidth' self.width= ['Image ImageWidth'].values[0] end if .include? 'Image ImageLength' self.length= ['Image ImageLength'].values[0] end if .include? 'Image XResolution' self.x_sampling_freq= ['Image XResolution'].values[0] end if .include? 'Image YResolution' self.y_sampling_freq= ['Image YResolution'].values[0] end if .include? 'Image ResolutionUnit' if (['Image ResolutionUnit'].values[0] == 3) self.sampling_unit=3 elsif (['Image ResolutionUnit'].values[0] == 2) self.sampling_unit=2 else self.sampling_unit=1 end end self.extent= srcfile.stat.size unless srcfile.nil? self.format= MIME[:jpg] end |