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.
Every reader returns nil for data that isn't a readable image.
Instance Method Summary collapse
-
#alpha? ⇒ Boolean?
Returns true if the image has an alpha channel.
-
#colorspace ⇒ String?
Returns the color space of the image as a string.
-
#content_type ⇒ String?
Returns the content type of the image.
-
#dimensions ⇒ Vector2d?
Returns the dimensions of the image as a vector.
-
#format ⇒ String?
Returns the name of the detected format.
-
#frame_count ⇒ Integer?
Returns the number of frames.
-
#height ⇒ Integer?
Returns the height of the image.
-
#initialize(data) ⇒ Metadata
constructor
A new instance of Metadata.
-
#valid? ⇒ Boolean
Returns true if the data is a readable image in a supported format.
-
#width ⇒ Integer?
Returns the width of the image.
Constructor Details
#initialize(data) ⇒ Metadata
Returns a new instance of Metadata.
17 18 19 |
# File 'lib/dynamic_image/metadata.rb', line 17 def initialize(data) @data = data end |
Instance Method Details
#alpha? ⇒ Boolean?
Returns true if the image has an alpha channel.
This is the presence of the channel, not of actual transparency: an image can carry a fully opaque alpha channel. Reading it costs nothing, where scanning the channel for transparency would mean decoding every pixel.
87 88 89 |
# File 'lib/dynamic_image/metadata.rb', line 87 def alpha? [:alpha] if valid? end |
#colorspace ⇒ String?
Returns the color space of the image as a string. The result will be one of the following: "rgb", "cmyk", "gray".
25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/dynamic_image/metadata.rb', line 25 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 ⇒ String?
Returns the content type of the image.
41 42 43 |
# File 'lib/dynamic_image/metadata.rb', line 41 def content_type reader.format.content_type if valid? end |
#dimensions ⇒ Vector2d?
Returns the dimensions of the image as a vector. EXIF rotation is applied, so these are the dimensions the image has once normalized.
56 57 58 |
# File 'lib/dynamic_image/metadata.rb', line 56 def dimensions Vector2d.new([:width], [:height]) if valid? end |
#format ⇒ String?
Returns the name of the detected format.
48 49 50 |
# File 'lib/dynamic_image/metadata.rb', line 48 def format reader.format.name if valid? end |
#frame_count ⇒ Integer?
Returns the number of frames. Animated formats can have more than one; everything else has a single frame.
77 78 79 |
# File 'lib/dynamic_image/metadata.rb', line 77 def frame_count [:frame_count] if valid? end |
#height ⇒ Integer?
Returns the height of the image.
70 71 72 |
# File 'lib/dynamic_image/metadata.rb', line 70 def height [:height] if valid? end |
#valid? ⇒ Boolean
Returns true if the data is a readable image in a supported format.
94 95 96 |
# File 'lib/dynamic_image/metadata.rb', line 94 def valid? @data && reader.valid_header? && != :invalid end |
#width ⇒ Integer?
Returns the width of the image.
63 64 65 |
# File 'lib/dynamic_image/metadata.rb', line 63 def width [:width] if valid? end |