Class: MagickMetadata
- Inherits:
-
Object
- Object
- MagickMetadata
- Defined in:
- lib/magick-metadata.rb
Instance Method Summary collapse
- #compression_percent ⇒ Object
- #dimensions ⇒ Object
- #file_size ⇒ Object
-
#has_transparency? ⇒ Boolean
Helper methods.
- #height ⇒ Object
-
#initialize(file_path) ⇒ MagickMetadata
constructor
A new instance of MagickMetadata.
- #resolution ⇒ Object
- #width ⇒ Object
Constructor Details
#initialize(file_path) ⇒ MagickMetadata
Returns a new instance of MagickMetadata.
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/magick-metadata.rb', line 3 def initialize( file_path ) # Create attr_accessors for all keys in the data_map data_map.each do |k, v| create_attr v end # Get the data for the image using 'identify' format_str = data_map.keys.map{|k|"%#{k}"}.join('|') data = %x[identify -format "#{format_str}" #{file_path}].chomp # Parse the data response and assign it to the instance values data.split('|').each_with_index do |val, idx| attr_name = data_map.values[idx] instance_variable_set("@#{attr_name}", val) end end |
Instance Method Details
#compression_percent ⇒ Object
40 41 42 |
# File 'lib/magick-metadata.rb', line 40 def compression_percent @image_compression_quality.to_f if @image_compression_quality end |
#dimensions ⇒ Object
28 29 30 |
# File 'lib/magick-metadata.rb', line 28 def dimensions [@current_width_in_pixels.to_i, @current_height_in_pixels.to_i] end |
#file_size ⇒ Object
32 33 34 |
# File 'lib/magick-metadata.rb', line 32 def file_size @file_size_of_image.scan(/\d/).join().to_i if @file_size_of_image end |
#has_transparency? ⇒ Boolean
Helper methods
24 25 26 |
# File 'lib/magick-metadata.rb', line 24 def has_transparency? @image_transparency_channel_enabled == 'True' end |
#height ⇒ Object
48 49 50 |
# File 'lib/magick-metadata.rb', line 48 def height dimensions[1] end |
#resolution ⇒ Object
36 37 38 |
# File 'lib/magick-metadata.rb', line 36 def resolution @x_resolution_density.scan(/\d/).join().to_i if @x_resolution_density end |
#width ⇒ Object
44 45 46 |
# File 'lib/magick-metadata.rb', line 44 def width dimensions[0] end |