Class: DynamicImage::Metadata

Inherits:
Object
  • Object
show all
Defined in:
lib/dynamic_image/metadata.rb

Overview

DynamicImage Metadata

Parses metadata from an image. Expects to receive image data as a binary string.

Instance Method Summary collapse

Constructor Details

#initialize(data) ⇒ Metadata

Returns a new instance of Metadata.



9
10
11
# File 'lib/dynamic_image/metadata.rb', line 9

def initialize(data)
  @data = data
end

Instance Method Details

#colorspaceObject

Returns the color space of the image as a string. The result will be one of the following: “rgb”, “cmyk”, “gray”.



15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/dynamic_image/metadata.rb', line 15

def colorspace
  return unless valid?

  case [:colorspace].to_s
  when /rgb/i
    "rgb"
  when /cmyk/i
    "cmyk"
  when /gray/i, /b-w/i
    "gray"
  end
end

#content_typeObject

Returns the content type of the image.



29
30
31
# File 'lib/dynamic_image/metadata.rb', line 29

def content_type
  reader.format.content_type if valid?
end

#dimensionsObject

Returns the dimensions of the image as a vector.



38
39
40
# File 'lib/dynamic_image/metadata.rb', line 38

def dimensions
  Vector2d.new([:width], [:height]) if valid?
end

#formatObject



33
34
35
# File 'lib/dynamic_image/metadata.rb', line 33

def format
  reader.format.name if valid?
end

#heightObject

Returns the height of the image.



48
49
50
# File 'lib/dynamic_image/metadata.rb', line 48

def height
  [:height] if valid?
end

#valid?Boolean

Returns true if the image is valid.

Returns:

  • (Boolean)


53
54
55
# File 'lib/dynamic_image/metadata.rb', line 53

def valid?
  @data && reader.valid_header? &&  != :invalid
end

#widthObject

Returns the width of the image.



43
44
45
# File 'lib/dynamic_image/metadata.rb', line 43

def width
  [:width] if valid?
end