Class: EXIFR::JPEG

Inherits:
Object
  • Object
show all
Defined in:
lib/exifr/jpeg.rb

Overview

JPEG decoder

Examples

EXIFR::JPEG.new('IMG_3422.JPG').width         # -> 2272
EXIFR::JPEG.new('IMG_3422.JPG').exif.model    # -> "Canon PowerShot G3"

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file) ⇒ JPEG

file is a filename or an IO object. Hint: use StringIO when working with slurped data like blobs.



30
31
32
33
34
35
36
# File 'lib/exifr/jpeg.rb', line 30

def initialize(file)
  if file.kind_of? String
    File.open(file, 'rb') { |io| examine(io) }
  else
    examine(file.dup)
  end
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args) ⇒ Object

Dispatch to EXIF. When no EXIF data is available but the method does exist for EXIF data nil will be returned.



57
58
59
60
61
# File 'lib/exifr/jpeg.rb', line 57

def method_missing(method, *args)
  super unless args.empty?
  super unless methods.include?(method.to_s)
  @exif.send method if defined?(@exif) && @exif
end

Instance Attribute Details

#app1sObject (readonly)

raw APP1 frames



27
28
29
# File 'lib/exifr/jpeg.rb', line 27

def app1s
  @app1s
end

#bitsObject (readonly)

number of bits per ??



18
19
20
# File 'lib/exifr/jpeg.rb', line 18

def bits
  @bits
end

#commentObject (readonly)

comment; a string if one comment found, an array if more, otherwise nil



21
22
23
# File 'lib/exifr/jpeg.rb', line 21

def comment
  @comment
end

#exifObject (readonly)

EXIF data if available



23
24
25
# File 'lib/exifr/jpeg.rb', line 23

def exif
  @exif
end

#exif_dataObject (readonly)

raw EXIF data



25
26
27
# File 'lib/exifr/jpeg.rb', line 25

def exif_data
  @exif_data
end

#heightObject (readonly)

image height



14
15
16
# File 'lib/exifr/jpeg.rb', line 14

def height
  @height
end

#widthObject (readonly)

image width



16
17
18
# File 'lib/exifr/jpeg.rb', line 16

def width
  @width
end

Class Method Details

.instance_methods(include_super = true) ⇒ Object

:nodoc:



73
74
75
# File 'lib/exifr/jpeg.rb', line 73

def instance_methods(include_super = true) # :nodoc:
  instance_methods_without_jpeg_extras(include_super) + TIFF::TAGS << "gps"
end

.instance_methods_without_jpeg_extrasObject



72
# File 'lib/exifr/jpeg.rb', line 72

alias instance_methods_without_jpeg_extras instance_methods

Instance Method Details

#exif?Boolean

Returns true when EXIF data is available.



39
40
41
# File 'lib/exifr/jpeg.rb', line 39

def exif?
  !exif.nil?
end

#methodsObject

:nodoc:



67
68
69
# File 'lib/exifr/jpeg.rb', line 67

def methods # :nodoc:
  super + TIFF::TAGS << "gps"
end

#respond_to?(method) ⇒ Boolean

:nodoc:



63
64
65
# File 'lib/exifr/jpeg.rb', line 63

def respond_to?(method) # :nodoc:
  super || methods.include?(method.to_s)
end

#thumbnailObject

Return thumbnail data when available.



44
45
46
# File 'lib/exifr/jpeg.rb', line 44

def thumbnail
  defined?(@exif) && @exif && @exif.jpeg_thumbnails && @exif.jpeg_thumbnails.first
end

#to_hashObject

Get a hash presentation of the image.



49
50
51
52
53
# File 'lib/exifr/jpeg.rb', line 49

def to_hash
  h = {:width => width, :height => height, :bits => bits, :comment => comment}
  h.merge!(exif) if exif?
  h
end