Class: RMagickMetadata
- Inherits:
-
Object
- Object
- RMagickMetadata
- Defined in:
- lib/rmagick-metadata.rb
Instance Method Summary collapse
- #compression_percent ⇒ Object
- #dimensions ⇒ Object
- #file_size ⇒ Object
-
#has_transparency? ⇒ Boolean
Helper methods.
- #height ⇒ Object
-
#initialize(file_path) ⇒ RMagickMetadata
constructor
A new instance of RMagickMetadata.
- #resolution ⇒ Object
- #width ⇒ Object
Constructor Details
#initialize(file_path) ⇒ RMagickMetadata
Returns a new instance of RMagickMetadata.
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/rmagick-metadata.rb', line 5 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
42 43 44 |
# File 'lib/rmagick-metadata.rb', line 42 def compression_percent @image_compression_quality.to_f if @image_compression_quality end |
#dimensions ⇒ Object
30 31 32 |
# File 'lib/rmagick-metadata.rb', line 30 def dimensions [@current_width_in_pixels.to_i, @current_height_in_pixels.to_i] end |
#file_size ⇒ Object
34 35 36 |
# File 'lib/rmagick-metadata.rb', line 34 def file_size @file_size_of_image.scan(/\d/).join().to_i if @file_size_of_image end |
#has_transparency? ⇒ Boolean
Helper methods
26 27 28 |
# File 'lib/rmagick-metadata.rb', line 26 def has_transparency? @image_transparency_channel_enabled == 'True' end |
#height ⇒ Object
50 51 52 |
# File 'lib/rmagick-metadata.rb', line 50 def height dimensions[1] end |
#resolution ⇒ Object
38 39 40 |
# File 'lib/rmagick-metadata.rb', line 38 def resolution @x_resolution_density.scan(/\d/).join().to_i if @x_resolution_density end |
#width ⇒ Object
46 47 48 |
# File 'lib/rmagick-metadata.rb', line 46 def width dimensions[0] end |