Sha256: 0eed0c0031b157dd9b9d580bdd12ca0608702bf27963134a62d06b2616ea4954

Contents?: true

Size: 1.27 KB

Versions: 67

Compression:

Stored size: 1.27 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 == 0
    puts "Specify one or more image filenames as arguments."
    exit
end


ARGV.each { |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"}"

    if img.properties.length > 0
        puts "   Properties:"
        img.properties { |name,value|
            puts %Q|      #{name} = "#{value}"|
        }
    end
}

Version data entries

67 entries across 67 versions & 2 rubygems

Version Path
rmagick-2.13.4 examples/describe.rb
rmagick-2.13.3 examples/describe.rb
rmagick-2.13.3.rc1 examples/describe.rb
rmagick-2.13.2 examples/describe.rb
rdp-rmagick-0.0.0 examples/describe.rb
rmagick-2.13.1 examples/describe.rb
rmagick-2.12.2 examples/describe.rb
rmagick-2.12.1 examples/describe.rb
rmagick-2.12.0 examples/describe.rb
rmagick-2.11.1 examples/describe.rb
rmagick-2.10.0 examples/describe.rb
rmagick-2.11.0 examples/describe.rb
rmagick-1.10.1 examples/describe.rb
rmagick-1.10.0 examples/describe.rb
rmagick-1.13.0 examples/describe.rb
rmagick-1.12.0 examples/describe.rb
rmagick-1.11.1 examples/describe.rb
rmagick-1.11.0 examples/describe.rb
rmagick-1.15.1 examples/describe.rb
rmagick-1.15.0 examples/describe.rb