encode text to image

Dar Scott dsc at swcp.com
Thu Aug 31 13:59:12 EDT 2006


On Aug 31, 2006, at 1:47 AM, paolo mazza wrote:

> I have to store an image in a MySQL database and I was told I could  
> store
> the text... it is not gonna work ... I thought it was like that....  
> but I
> wanted be sure that there was not a way to recover the imagedata  
> from the
> text.
>
> So, I have to encode and decode the image data ... I tryed this  
> way, but
> unfortunately , when I decode image data and upload it in in the  
> database,
> some chars get lost.

The name "the text" for the property of the image that stores the  
standard compressed image is a little strange since the is binary.   
Perhaps it comes from the fact that you can do this...

    put imageValue into image "Image 1"

... and it is the same as this...

    set the text of image "Image 1" to imageValue

...just the same as setting the text of a field.

If you have control over the type, you can store that in MySQL safely  
as a BLOB type, perhaps LONGBLOB.  If you must store it as TEXT, you  
might be OK.  If you are seeing roundtrip conversion problems, then  
you might want to convert the image to base64 using base64Encode()  
and back using base64Decode().  The function base64Encode() maps  
arbitrary binary data into a subset of ASCII characters.

The roundtrip problem (if you have one) might not be in MySQL, but in  
the interface.

Dar Scott



More information about the use-livecode mailing list