Re: file type check method
Re: file type check method
- Subject: Re: file type check method
- From: Freek Dijkstra <email@hidden>
- Date: Wed, 20 Oct 2004 11:50:55 +0200
On 20-10-2004 7:12, "김경옥" <email@hidden> wrote:
>
I'd like to check image file types and exculd unsupported image type file in
>
the open panel.
>
Is there any way that I can check the file type not by file extension for
>
image files?
There is a Unix tool called 'file', which determines the file type by using
a "magic" file, which contains pattern matches for file types, including
image files (for example, GIF files typically start with "GIF89a").
This is not fool-proof, but often works very well. See 'man file' for more
information.
If you use it, you may want to consider adding the file binary, and magic
file to your distribution, rather then relying on the availabilty in
/usr/bin/file. Be aware of license issues if you combine the distribution
though.
Alternatively, you can just try to open any file using the Cocoa functions.
I've noticed that it works, irrespective of the extension. Obviously, you
need to check for errors to prevent people from opening non-image files. But
you probably need to add such a check anyway, since the above file probably
does not detect broken image files (for example incomplete jpg files).
Kind regards,
Freek Dijkstra
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden