Find out which image types/file extensions are supported

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
codymanix
Posts: 19
Joined: 2008-02-20T20:49:46-07:00

Find out which image types/file extensions are supported

Post by codymanix »

Hi! I'am developing a file browser which displays thumbnails for image files.
The problem is that I don't know in advance whether a given file is an image or not, so I have to load each file as MagickImage and see if an error occures.
The problem is that this is extremely slow if only a few files are really images or the files are big, it seems that imagemagick scans the whole file to the end to determine whether it is a valid image.

My question now is:
Is there a method which can tell me whether a given file extension is supported?
Or is there any fail-fast method to determine if a given file can be loaded as image with imagemagick?
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: Find out which image types/file extensions are supported

Post by magick »

Use PingImage() to quickly and efficiently determine the image format and size of an arbitrary file.
codymanix
Posts: 19
Joined: 2008-02-20T20:49:46-07:00

Re: Find out which image types/file extensions are supported

Post by codymanix »

PingImage does exactly the same thing as ReadImage; it tests wheather a given file is an Image, and if it is then it reads Imageinformation, and in case of Readimage the pixels.
I tested it, the have exactly the same performance when called on non-image files.

Isn't there any way to query the supported file extensions, I mean the plugins have to register theirselves do they hjave any information about the file extensions they are able to read?
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: Find out which image types/file extensions are supported

Post by magick »

Use GetMagickList() to get a list of supported image types.
codymanix
Posts: 19
Joined: 2008-02-20T20:49:46-07:00

Re: Find out which image types/file extensions are supported

Post by codymanix »

Thank you very much, this is exactly what I was looking for!
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Find out which image types/file extensions are supported

Post by anthony »

For efficent file type determination (image or otherwise) the better utility is the non-IM command "file".


Images can then be tested with ImageMagick for errors and format failures, as well as actual image processing.

As 'Bob the Builder' says.. Use the right tool for the job!
(You may need kids to have heard this little gem!)
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
codymanix
Posts: 19
Joined: 2008-02-20T20:49:46-07:00

Re: Find out which image types/file extensions are supported

Post by codymanix »

If you mean with "file" the linux command..
I program for windows so I can't use that.
Even if the "file" command determines that a given file is an Image doesn't give me any guarantee that it is supported by imagemagick and also the file command may not know all of the types supported by imagemagick so that would not be of great use.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Find out which image types/file extensions are supported

Post by anthony »

There are dos versions of the "file" command and the "magic" data that it uses. You are right in that it does not tell you if IM can support the format, but it is good as a 'first cut' for the input files you want to process.

Code: Select all

convert -list format
Will give you a list of formats your version of IM was built with. However that is no guarantee that IM knows that specific format as the delegate library (DLL) the 'coder' module requires may not be installed.

So you should have three layers of file sorting.

file
IM format list (compare against the "file" output)
Have IM attempt to read and process the file.

NOTE: for robustness you should not assume that the files 'suffix' is correct. It usually is, but a SPAM or VIRUS attempt may leave junk hidden with the wrong suffix. The "file" method will help sort out that horridness.

As my old university lecturer said... Application Programs are often up to 90% input sanity checking and decoding. Without such checking your code will fail in the real world!

Image processing is no exception.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
codymanix
Posts: 19
Joined: 2008-02-20T20:49:46-07:00

Re: Find out which image types/file extensions are supported

Post by codymanix »

OK, thank you I'll give it a try..
Post Reply