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.



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

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.



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

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



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

def app1s
  @app1s
end

#bitsObject (readonly)

number of bits per ??



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

def bits
  @bits
end

#commentObject (readonly)

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



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

def comment
  @comment
end

#exifObject (readonly)

EXIF data if available



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

def exif
  @exif
end

#exif_dataObject (readonly)

raw EXIF data



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

def exif_data
  @exif_data
end

#heightObject (readonly)

image height



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

def height
  @height
end

#widthObject (readonly)

image width



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

def width
  @width
end

Class Method Details

.instance_methods(include_super = true) ⇒ Object

:nodoc:



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

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

.instance_methods_without_jpeg_extrasObject



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

alias instance_methods_without_jpeg_extras instance_methods

Instance Method Details

#exif?Boolean

Returns true when EXIF data is available.



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

def exif?
  !exif.nil?
end

#methodsObject

:nodoc:



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

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

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

:nodoc:



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

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.



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

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

#to_hashObject

Get a hash presentation of the image.



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

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