Page 1 of 1

Fast way to get Image Info (size, datatype info)

Posted: 2008-02-18T17:55:04-07:00
by nicolas1
Is there any way to get image dimensions and datatype data (located usually in image file header) fastly? "ping" function reads whole imagefile into memory and then return this data. This causes significan and not necessary delay...

Re: Fast way to get Image Info (size, datatype info)

Posted: 2008-02-18T18:59:21-07:00
by fmw42
identify <image>

or for more information

identify -verbose info: <image>

Re: Fast way to get Image Info (size, datatype info)

Posted: 2008-02-18T19:44:34-07:00
by nicolas1
Inspecting source I found that "identify" uses "PingImage" internally.

I mean function which read only image header... not a whole imagefile (do not confuse reading with decoding).

Re: Fast way to get Image Info (size, datatype info)

Posted: 2008-02-18T19:58:09-07:00
by magick
PingImage() reads the entire image but throws the pixels away so it is fast and memory efficient. ImageMagick does not have a method to just read an image header but not the pixels.

Re: Fast way to get Image Info (size, datatype info)

Posted: 2008-02-18T20:05:25-07:00
by nicolas1
"PingImage" is much faster then decoding, but noticable slow then just read header. For example, if jpeg image is 16 megs, delay is significant. Maybe better to have api, which is invariant of image size. Just a suggestion.
For example, usually it is necessary to make some precalculations depending on image size, before really decoding it. The faster way to get image size before docoding, results in more interactive program.

Btw, it is possible to modify current IM code ("ReadImage" fucntion)?

Re: Fast way to get Image Info (size, datatype info)

Posted: 2008-02-19T07:16:14-07:00
by magick
JPEG is a special case. Set the image_info->size member to something small like 16x16 and PingImage() will return quickly.