Page 1 of 1

Format of image file copied on the clipboard

Posted: Wed Feb 25, 2015 2:47 pm
by designtech
Hello everyone,

Having fun with livecode however I have a question and a clarification that I've not seen answered elsewhere.

When I 'dump' an image copied on the clipboard (from an external program, say a web browser) I have found
out that regardless of the format (gif, jpg etc) of the original image, the output is always in PNG format.
Is that the expected behaviour? See example code below

Code: Select all

--example code
--I put the contents of an image on the clipbaord to currentclipdata var
   put clipBoardData["image"] into currentclipdata["contents"] 
--then dump the contents of the clipboard on my desktop as clipImage.jpg
--and open it with an image editor 
     put specialFolderPath("Desktop") into tmpPath
      set the defaultFolder to tmpPath
      put  currentclipdata["contents"] into URL ("binfile:" & tmpPath & "/clipImage.jpg")     
      launch document  tmpPath & "/clipImage.jpg"
--voila I find my image editor complain that 'clipImage' has the WRONG extension
--that the image should actually be 'clipImage.png' even if the original image was jpg format
My question: is there a way to determine the type/format of an image file on the clipboard without
necessarily having access to it's filename (extension). I am asking this also because I know it's possible to
have a mis-named image file. For example a user could have an image file mis-named as 'myImage.png'
that is actually in JPG format. I know how to determine the format from filename extension, but what
happens if that is unreliable.

Helpers appreciated in advance. :D

David Ok

Re: Format of image file copied on the clipboard

Posted: Wed Feb 25, 2015 4:12 pm
by Simon
Hi David,
Welcome to the forum :)

I see that the first line of a png is %PNG which I think is pretty reliable (I've seen it there for years), I'm not sure of the consistency of the first line of jpg.
OK I'm no image guru but try checking that and see if it works with your data.

Simon

Re: Format of image file copied on the clipboard

Posted: Wed Feb 25, 2015 4:22 pm
by Klaus
Hi David,

yes, looks like LC alway uses the PNG format for clipboarddata!

Just made a test and copied parts of a JPG image in Preview and it turned
out as PNG in the clipboard when checking in LC -> byte 1 to 4 = %PNG

This is not dicumented anywhere, but as Simon says, I also think this is reliable.

On the other hand you can always put the clipboarddata into an existing and
maybe hidden image object and then export htat as JPG or PNG if you like.

The user will not be able to tell the difference :D


Best

Klaus

Re: Format of image file copied on the clipboard

Posted: Wed Feb 25, 2015 4:27 pm
by designtech
Hello Simon and Klaus

Thanks for your response.
Simon wrote:I see that the first line of a png is %PNG which I think is pretty reliable
Yeah been seeing that in my variables during debugging and wondering what it meant.
Thanks for sharing this info.
Klaus wrote:On the other hand you can always put the clipboarddata into an existing and
maybe hidden image object and then export htat as JPG or PNG if you like.
Klaus hmmm.. Nice idea. I'll look into this.

Thanks