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"

Defined Under Namespace

Classes: Reader

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.



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

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.



59
60
61
62
63
# File 'lib/exifr/jpeg.rb', line 59

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

Instance Attribute Details

#app1sObject (readonly)

raw APP1 frames



29
30
31
# File 'lib/exifr/jpeg.rb', line 29

def app1s
  @app1s
end

#bitsObject (readonly)

number of bits per ??



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

def bits
  @bits
end

#commentObject (readonly)

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



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

def comment
  @comment
end

#exifObject (readonly)

EXIF data if available



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

def exif
  @exif
end

#exif_dataObject (readonly)

raw EXIF data



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

def exif_data
  @exif_data
end

#heightObject (readonly)

image height



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

def height
  @height
end

#widthObject (readonly)

image width



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

def width
  @width
end

Class Method Details

.instance_methods(include_super = true) ⇒ Object

:nodoc:



79
80
81
# File 'lib/exifr/jpeg.rb', line 79

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

.instance_methods_without_jpeg_extrasObject



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

alias instance_methods_without_jpeg_extras instance_methods

Instance Method Details

#exif?Boolean

Returns true when EXIF data is available.

Returns:

  • (Boolean)


41
42
43
# File 'lib/exifr/jpeg.rb', line 41

def exif?
  !exif.nil?
end

#methods(regular = true) ⇒ Object

:nodoc:



69
70
71
72
73
74
75
# File 'lib/exifr/jpeg.rb', line 69

def methods(regular=true) # :nodoc:
  if regular
    super + TIFF::TAGS << :gps
  else
    super
  end
end

#respond_to?(method, include_all = false) ⇒ Boolean

:nodoc:

Returns:

  • (Boolean)


65
66
67
# File 'lib/exifr/jpeg.rb', line 65

def respond_to?(method, include_all = false) # :nodoc:
  super || methods.include?(method) || (include_all && private_methods.include?(method))
end

#thumbnailObject

Return thumbnail data when available.



46
47
48
# File 'lib/exifr/jpeg.rb', line 46

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

#to_hashObject

Get a hash presentation of the image.



51
52
53
54
55
# File 'lib/exifr/jpeg.rb', line 51

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