Invalid Image File / Original Image Size

Phil Davis phil at pdslabs.net
Mon Feb 17 16:57:52 EST 2020


Hi Ralph,

Certainly Klaus's approach will work. Here is another that works.

As you know, image files have "signatures" in their headers to identify 
what kind of files they are:

    https://en.wikipedia.org/wiki/List_of_file_signatures
    (the "ISO 8859-1" column)


Once you know the signatures of the image file types you want to allow, 
you could do something like this:

on mouseUp
     answer file "Pick an image file:"
     if it is empty then exit to top

     answer isSupportedImage(it)
end mouseUp


function isSupportedImage pPath
     # Allow JPG, PNG and GIF images.

     put byte 1 to 12 of url ("binfile:" & pPath) into tHeader
     switch
         case "JFIF" is in tHeader
         case "PNG" is in tHeader
         case "GIF" is in tHeader
             return true
             break
         default
             return false
             break
     end switch
end isSupportedImage


I have used this approach in projects before and it seems to work reliably.

Phil Davis



On 2/17/20 1:08 PM, Ralph DiMola via use-livecode wrote:
> What's the best way to know if I set the filename of an image control and
> the file is either not an image or in an unsupported format? I'm getting
> https links to unknown images so I check images before app deployment.
>
> After resizing an image is there a way to know the original dimensions? Just
> wondering? I now save the original x/y sizes in properties so I know them
> after a resize.
>
> Thanks
>
> Ralph DiMola
> IT Director
> Evergreen Information Services
> rdimola at evergreeninfo.net
>
>
> _______________________________________________
> use-livecode mailing list
> use-livecode at lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode
>

-- 
Phil Davis
503-307-4363




More information about the use-livecode mailing list