Detecting Image type from raw bytes

Questions and postings pertaining to the development of ImageMagick, feature enhancements, and ImageMagick internals. ImageMagick source code and algorithms are discussed here. Usage questions which are too arcane for the normal user list should also be posted here.
Post Reply
roflson
Posts: 4
Joined: 2014-04-10T14:44:17-07:00
Authentication code: 6789

Detecting Image type from raw bytes

Post by roflson »

In order to speed up my image processing, I use the jpeg:size hint to give the JPEG decoder more efficiency.

However, I don't want to do this blindly. How can I detect an image type from the raw bytes before calling BlobToImage?

I could write code to inspect the header, but I think Imagemagick should be able to do this too?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Detecting Image type from raw bytes

Post by fmw42 »

see string format at http://www.imagemagick.org/script/escape.php

%m image file format (file magic)

Code: Select all

identify -format "%m" yourimage
roflson
Posts: 4
Joined: 2014-04-10T14:44:17-07:00
Authentication code: 6789

Re: Detecting Image type from raw bytes

Post by roflson »

I am doing this in-memory with the MagickCore interface. I need to determine an image type from the raw bytes before calling BlobToImage
Post Reply