環境とかバージョンとか。


$ uname -mvrs
Darwin 10.6.0 Darwin Kernel Version 10.6.0: Wed Nov 10 18:13:17 PST 2010; root:xnu-1504.9.26~3/RELEASE_I386 i386
 
$ ruby -v
ruby 1.8.7 (2010-12-23 patchlevel 330) [i686-darwin10]
 
$ gem list | grep rmagick
rmagick (2.13.1)

サンプルコード。
RMagick の Image オブジェクトのプロパティにいろいろ情報がセットされてるのでそれを見る感じ。


$ cat ./imageinfo.rb
require 'rubygems'
require 'RMagick'
 
# URLが指定できるのはラクでいいね!
files = [
  'http://www.nilab.info/zlashdot32x32.png',
  'http://www.nilab.info/z3/z3_kohaku.png',
  'http://www.nilab.info/zurazure2/20100124_orientation6.jpg',
  'http://www.nilab.info/favicon.ico',
  'http://www.nilab.info/lib/image/icon/twitter.ico',
  'http://www.imagemagick.org/image/logo.jpg',
  'http://map.olp.yahooapis.jp/OpenLocalPlatform/V1/static?appid=nilabinfo&e=0,255,0,0,5,0,255,0,127,35.681564010675,139.76721006431,50000&z=8&width=300&height=200',
]
 
files.each{|file|
  puts "----------------------------------------"
  begin
    images = Magick::Image.read(file)
    images.each{|image|
      puts "#{file}"
      puts "filename: #{image.filename}"
      puts "format: #{image.format}"
      puts "type: #{image.image_type}"
      puts "colorspace: #{image.colorspace}"
      puts "depth: #{image.depth}"
      puts "gamma: #{image.gamma}"
      puts "fuzz: #{image.fuzz}"
      puts "orientation: #{image.orientation}"
      puts "background color: #{image.background_color}"
      puts "width: #{image.columns} px"
      puts "height: #{image.rows} px"
      puts "filesize: #{image.filesize} bytes"
    }
  rescue
    $stderr.puts $!.to_s
    $stderr.puts $!.backtrace.inspect
  end
}

実行結果。
.ico ファイルは読み込めないっぽい。


$ ruby ./imageinfo.rb 
----------------------------------------
http://www.nilab.info/zlashdot32x32.png
filename: zlashdot32x32.png
format: PNG
type: TrueColorMatteType
colorspace: RGBColorspace
depth: 8
gamma: 0.0
fuzz: 0.0
orientation: UndefinedOrientation
background color: white
width: 32 px
height: 32 px
filesize: 2435 bytes
----------------------------------------
http://www.nilab.info/z3/z3_kohaku.png
filename: z3_kohaku.png
format: PNG
type: TrueColorMatteType
colorspace: RGBColorspace
depth: 8
gamma: 0.0
fuzz: 0.0
orientation: UndefinedOrientation
background color: white
width: 46 px
height: 46 px
filesize: 4350 bytes
----------------------------------------
http://www.nilab.info/zurazure2/20100124_orientation6.jpg
filename: 20100124_orientation6.jpg
format: JPEG
type: TrueColorType
colorspace: RGBColorspace
depth: 8
gamma: 0.0
fuzz: 0.0
orientation: RightTopOrientation
background color: white
width: 2048 px
height: 1536 px
filesize: 1119383 bytes
----------------------------------------
no data returned `http://www.nilab.info/favicon.ico' @ error/url.c/ReadURLImage/229
["./imageinfo.rb:17:in `read'", "./imageinfo.rb:17", "./imageinfo.rb:14:in `each'", "./imageinfo.rb:14"]
----------------------------------------
no data returned `http://www.nilab.info/lib/image/icon/twitter.ico' @ error/url.c/ReadURLImage/229
["./imageinfo.rb:17:in `read'", "./imageinfo.rb:17", "./imageinfo.rb:14:in `each'", "./imageinfo.rb:14"]
----------------------------------------
http://www.imagemagick.org/image/logo.jpg
filename: logo.jpg
format: JPEG
type: TrueColorType
colorspace: RGBColorspace
depth: 8
gamma: 0.0
fuzz: 0.0
orientation: UndefinedOrientation
background color: white
width: 123 px
height: 118 px
filesize: 16246 bytes
----------------------------------------
http://map.olp.yahooapis.jp/OpenLocalPlatform/V1/static?appid=nilabinfo&e=0,255,0,0,5,0,255,0,127,35.681564010675,139.76721006431,50000&z=8&width=300&height=200
filename: static?appid=nilabinfo&e=0,255,0,0,5,0,255,0,127,35.681564010675,139.76721006431,50000&z=8&width=300&height=200
format: PNG
type: PaletteType
colorspace: RGBColorspace
depth: 8
gamma: 0.0
fuzz: 0.0
orientation: UndefinedOrientation
background color: white
width: 300 px
height: 200 px
filesize: 27797 bytes

Ref. RMagick 2.12.0: class Image (attribute methods)

tags: ruby rmagick

Posted by NI-Lab. (@nilab)