Page 1 of 1
Find out which image types/file extensions are supported
Posted: 2008-02-24T18:14:46-07:00
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?
Re: Find out which image types/file extensions are supported
Posted: 2008-02-24T18:26:11-07:00
by magick
Use PingImage() to quickly and efficiently determine the image format and size of an arbitrary file.
Re: Find out which image types/file extensions are supported
Posted: 2008-02-26T17:10:17-07:00
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?
Re: Find out which image types/file extensions are supported
Posted: 2008-02-26T17:19:08-07:00
by magick
Use GetMagickList() to get a list of supported image types.
Re: Find out which image types/file extensions are supported
Posted: 2008-02-26T17:52:17-07:00
by codymanix
Thank you very much, this is exactly what I was looking for!
Re: Find out which image types/file extensions are supported
Posted: 2008-03-02T18:52:28-07:00
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!)
Re: Find out which image types/file extensions are supported
Posted: 2008-03-03T07:32:26-07:00
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.
Re: Find out which image types/file extensions are supported
Posted: 2008-03-03T18:46:46-07:00
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.
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.
Re: Find out which image types/file extensions are supported
Posted: 2008-03-04T09:30:17-07:00
by codymanix
OK, thank you I'll give it a try..