Class: Cul::Image::Properties::Tiff

Inherits:
Base
  • Object
show all
Defined in:
lib/cul_image_props/image/properties/types.rb

Constant Summary

Constants inherited from Base

Base::BASE_XML

Instance Attribute Summary

Attributes inherited from Base

#nodeset

Instance Method Summary collapse

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) ⇒ Tiff

Returns a new instance of Tiff.



305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
# File 'lib/cul_image_props/image/properties/types.rb', line 305

def initialize(srcfile=nil)
  super
  header_bytes = @src.read(14)
  case header_bytes[0...4].unpack('C*')
  when Cul::Image::Magic::TIFF_INTEL_LE
    @endian = header_bytes[12]
  when Cul::Image::Magic::TIFF_MOTOROLA_BE
    @endian = header_bytes[12]
  else
    raise "Source file is not a tiff #{hex_inspect(header_bytes[0...4])}" 
  end
  @src.rewind
  tags = Cul::Image::Properties::Exif.process_file(srcfile)
  if tags.include? 'Image ImageWidth'
    self.width= tags['Image ImageWidth'].values[0]
  end
  if tags.include? 'Image ImageLength'
    self.length= tags['Image ImageLength'].values[0]
  end
  if tags.include? 'Image XResolution'
    self.x_sampling_freq= tags['Image XResolution'].values[0].inspect
  end
  if tags.include? 'Image YResolution'
    self.y_sampling_freq= tags['Image YResolution'].values[0].inspect
  end
  if tags.include? 'Image ResolutionUnit'
    if (tags['Image ResolutionUnit'].values[0] == 3)
      self.sampling_unit=3
    elsif (tags['Image ResolutionUnit'].values[0] == 2)
      self.sampling_unit=2
    else
      self.sampling_unit=1
    end
  end
  # do stuff with tags
  self.extent= srcfile.stat.size unless srcfile.nil?
  self.format=MIME[:tif]
end