Is this expected, or a bug?

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
pmurray

Is this expected, or a bug?

Post by pmurray »

Hi, just wondering if this behaviour is expected? If I ping the image it always says it's in Greyscale, even though the file is not. If I read the entire image, it correctly returns false.

I get the same true/false result with any RGB file I try.

Code: Select all

irb(main):001:0> require 'RMagick'
=> true
irb(main):002:0> i = Magick::Image.ping('test.jpg').first
=> test.jpg JPEG 1600x1084 1600x1084+0+0 DirectClass 8-bit 485kb
irb(main):003:0> i.grey?
=> true
irb(main):004:0> i.colorspace
=> RGBColorspace=1
irb(main):005:0> i = Magick::Image.read('test.jpg').first
i=> test.jpg JPEG 1600x1084 1600x1084+0+0 DirectClass 8-bit 485kb
irb(main):006:0> i.grey?
=> false
irb(main):007:0> Magick::Version
=> "RMagick 2.9.1"
irb(main):008:0> Magick::Magick_version
=> "ImageMagick 6.5.1-1 2009-04-20 Q16 http://www.imagemagick.org"
Interestingly, it works as expected with a much older version of ImageMagick,

Code: Select all

irb(main):001:0> require 'RMagick'
=> true
irb(main):002:0> puts Magick::Version, Magick::Magick_version
RMagick 2.3.0
ImageMagick 6.3.7 03/31/08 Q16 http://www.imagemagick.org
=> nil
irb(main):003:0> Magick::Image.ping('test.jpg').first.grey?
=> false
irb(main):004:0> Magick::Image.read('test.jpg').first.grey?
=> false
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: Is this expected, or a bug?

Post by magick »

Ping() is light-weight and only reads the image meta-data but not the image pixels. Therefore the attributes associated with the pixels are undefined. If you want to attributes associated with the image pixels, use Read() instead of Ping().
pmurray

Re: Is this expected, or a bug?

Post by pmurray »

Is there anyway I can tell if an Image is a greyscale one without read'ing the entire image? As I'm dealing with some large images, this gets very slow.

How come this behaves as expected in prior versions? Does ping actually load the image data in those cases?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Is this expected, or a bug?

Post by fmw42 »

in command line,

convert image -ping -format "%[colorspace]" info:

e.g.
convert rose: -colorspace gray rose_gray.png
convert rose_gray.png -ping -format "%[colorspace]" info:

returns:
Gray
Post Reply