Sha256: b4c78261e65c88b8f3792429e2aba4983b3c4d1bd031c88bc1e53ae769abeca3

Contents?: true

Size: 1.18 KB

Versions: 6

Compression:

Stored size: 1.18 KB

Contents

# Purpose: Demonstrate getting information from the image attributes.
# Usage: describe.rb filename1 [filename2...]
# Notes: The output is similar to ImageMagick's identify command.

require 'rmagick'

puts <<END_INFO

This example shows how to extract attributes from an image.

END_INFO

if ARGV.length.zero?
  puts 'Specify one or more image filenames as arguments.'
  exit
end

ARGV.each do |file|
  puts file
  img = Magick::Image.read(file).first
  puts "   Format: #{img.format}"
  puts "   Geometry: #{img.columns}x#{img.rows}"
  puts '   Class: ' + case img.class_type
                      when Magick::DirectClass
                        'DirectClass'
                      when Magick::PseudoClass
                        'PseudoClass'
                      end
  puts "   Depth: #{img.depth} bits-per-pixel"
  puts "   Colors: #{img.number_colors}"
  puts "   Filesize: #{img.filesize}"
  puts "   Resolution: #{img.x_resolution.to_i}x#{img.y_resolution.to_i} "\
       "pixels/#{img.units == Magick::PixelsPerInchResolution ? 'inch' : 'centimeter'}"

  next if img.properties.empty?

  puts '   Properties:'
  img.properties do |name, value|
    puts %(      #{name} = "#{value}")
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
rmagick-4.1.0.rc2 examples/describe.rb
rmagick-4.1.0.rc1 examples/describe.rb
rmagick-4.0.0 examples/describe.rb
rmagick-3.2.0 examples/describe.rb
rmagick-3.1.0 examples/describe.rb
rmagick-3.0.0 examples/describe.rb