Is a file an image?

Jan Schenkel janschenkel at yahoo.com
Wed Jan 27 06:57:08 EST 2010


--- On Tue, 1/26/10, David Bovill <david at architex.tv> wrote:
> I've just dug out this very old and
> pretty untested script for detecting
> whether a file is an image. Seems to sort of work on OSX -
> included here for
> insiration :) Does anyone know a better way to do this?
> 

Why go through the trouble of checking the extension and the content of the file, when you can let Rev decide if it supports that particular file as a valid image? :-)

Make a new stack with a button with the following script:
##
on mouseUp
   answer file "Pick an image file"
   if the result is "Cancel" then exit mouseUp
   answer "Is a supported image format:" && IsAnImageFile(it)
end mouseUp

function IsAnImageFile pFilePath
   local tIsAnImageFile
   --
   lock screen
   create image
   set the filename of the last image to pFilePath
   --> if the set fails, the result will tell you
   put (the result is empty) into tIsAnImageFile
   delete the last image
   return tIsAnImageFile
end IsAnImageFile
##

Click the button, select an image file, and it should be 'true' - select a Word document or something else that is definitely not an image, and yous should see 'false'.

Cheers,

Jan Schenkel
=====
Quartam Reports & PDF Library for Revolution
<http://www.quartam.com>

=====
"As we grow older, we grow both wiser and more foolish at the same time."  (La Rochefoucauld)



      




More information about the use-livecode mailing list