Class: MagickMetadata

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

Instance Method Summary collapse

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_percentObject



40
41
42
# File 'lib/magick-metadata.rb', line 40

def compression_percent
  @image_compression_quality.to_f if @image_compression_quality
end

#dimensionsObject



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_sizeObject



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

Returns:

  • (Boolean)


24
25
26
# File 'lib/magick-metadata.rb', line 24

def has_transparency?
  @image_transparency_channel_enabled == 'True'
end

#heightObject



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

def height
  dimensions[1]
end

#resolutionObject



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

#widthObject



44
45
46
# File 'lib/magick-metadata.rb', line 44

def width
  dimensions[0]
end