Class: DynamicImage::Metadata
- Inherits:
-
Object
- Object
- DynamicImage::Metadata
- Defined in:
- lib/dynamic_image/metadata.rb
Overview
DynamicImage Metadata
Parses metadata from an image. Accepts a Pathname, IO, or binary string.
Instance Method Summary collapse
-
#colorspace ⇒ Object
Returns the color space of the image as a string.
-
#content_type ⇒ Object
Returns the content type of the image.
-
#dimensions ⇒ Object
Returns the dimensions of the image as a vector.
- #format ⇒ Object
-
#height ⇒ Object
Returns the height of the image.
-
#initialize(data) ⇒ Metadata
constructor
A new instance of Metadata.
-
#valid? ⇒ Boolean
Returns true if the image is valid.
-
#width ⇒ Object
Returns the width of the image.
Constructor Details
#initialize(data) ⇒ Metadata
Returns a new instance of Metadata.
8 9 10 |
# File 'lib/dynamic_image/metadata.rb', line 8 def initialize(data) @data = data end |
Instance Method Details
#colorspace ⇒ Object
Returns the color space of the image as a string. The result will be one of the following: “rgb”, “cmyk”, “gray”.
14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/dynamic_image/metadata.rb', line 14 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_type ⇒ Object
Returns the content type of the image.
28 29 30 |
# File 'lib/dynamic_image/metadata.rb', line 28 def content_type reader.format.content_type if valid? end |
#dimensions ⇒ Object
Returns the dimensions of the image as a vector.
37 38 39 |
# File 'lib/dynamic_image/metadata.rb', line 37 def dimensions Vector2d.new([:width], [:height]) if valid? end |
#format ⇒ Object
32 33 34 |
# File 'lib/dynamic_image/metadata.rb', line 32 def format reader.format.name if valid? end |
#height ⇒ Object
Returns the height of the image.
47 48 49 |
# File 'lib/dynamic_image/metadata.rb', line 47 def height [:height] if valid? end |
#valid? ⇒ Boolean
Returns true if the image is valid.
52 53 54 |
# File 'lib/dynamic_image/metadata.rb', line 52 def valid? @data && reader.valid_header? && != :invalid end |
#width ⇒ Object
Returns the width of the image.
42 43 44 |
# File 'lib/dynamic_image/metadata.rb', line 42 def width [:width] if valid? end |