Base64Decode....again

Anything beyond the basics in using the LiveCode language. Share your handlers, functions and magic here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Thalor
Posts: 6
Joined: Thu Feb 12, 2015 4:35 pm

Base64Decode....again

Post by Thalor » Thu Feb 12, 2015 4:44 pm

I know this has been hashed and rehashed, but I cannot get this to work at all.

I have

Two image areas (Image1, Image2)
Two Buttons (Button1, Button2)
One Text field (text)

I'm trying a proof of concept for future development. (I NEED to store images in a DB)

At any rate the way it is supposed to go is:

1. I load a picture into Image1 (using the properties inspector)
2. Pushing button1 it will base64encrypt the imagedata of Image1 and store it in field "text"
3. Pushing button2 it will base64decrypt field "text" and place it into Image2


What I have for script:

Button1

Code: Select all

on mouseUp
   put base64encode(the imagedata of image "Image1") into field "text"
end mouseUp
Button2

Code: Select all

on mouseUp
   local decodedBinData
   put base64decode (field "text") into decodedBinData
   put decodedBinData into img "Image2"
end mouseUp
What happens:

When I push button1 it does put what appears to be a text string into field "text"
When I push button2 it doesnt put the image back into Image2

I've searched and read, re-read and copied all I can. Now I make an impassioned plea for some help.

Thanks in advance.

Klaus
Posts: 14208
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Base64Decode....again

Post by Klaus » Thu Feb 12, 2015 4:57 pm

Hi Thalor,

1. welcome to the forum! :D

2. I think when saving the IMAGEDATA, then you will also have to set it again!

Try this:

Code: Select all

on mouseUp
   local decodedBinData
   put base64decode (field "text") into decodedBinData
   set the imagedata of img "Image2" to decodedBinData
end mouseUp
Hint:
Using and setting imagedata requires that both images (source and target) have the SAME (sic!) dimensions (width and height)!
If that is not the case, you will get some more or less colorful garbage :D


Best

Klaus

Thalor
Posts: 6
Joined: Thu Feb 12, 2015 4:35 pm

Re: Base64Decode....again

Post by Thalor » Thu Feb 12, 2015 5:04 pm

One word. D'oh

Thank you so much. I can't believe how I missed that.

Thanks for the quick reply. I can get back to regrowing the hair that I pulled out.

T

Klaus
Posts: 14208
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Base64Decode....again

Post by Klaus » Thu Feb 12, 2015 5:27 pm

Thalor wrote:I can get back to regrowing the hair that I pulled out.
Good luck! :D

Thalor
Posts: 6
Joined: Thu Feb 12, 2015 4:35 pm

Re: Base64Decode....again

Post by Thalor » Thu Feb 12, 2015 5:31 pm

Interesting thing.

It all works. I can select an image. Put it into Image1, encode it and store it in MYSQL. I can retrieve it from MYSQL, decode and put it in Image2

HOWEVER

If Image1 and Image2 are different sizes (Height and Width) the image gets messed up

Any ideas?

I've been looking at re-sizing but all the examples are going from larger to smaller. I need to make it larger from a smaller.

It messes the image when I attempt it.
Last edited by Thalor on Thu Feb 12, 2015 6:00 pm, edited 1 time in total.

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10057
Joined: Sat Apr 08, 2006 7:05 am
Contact:

Re: Base64Decode....again

Post by FourthWorld » Thu Feb 12, 2015 5:54 pm

Odd: when I first ran your code I also got a blank img 2. But then I manually rewrote the handler, and now it works.

At first I thought perhaps there might be some odd non-printing character in the script, but then I went back and pasted your code again and now it works still.

At this point I can't find a way to get it to _not_ work, so I'm unable to be of further help.

You might try retyping the second handler just to see if it changes for you as it did for me.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10057
Joined: Sat Apr 08, 2006 7:05 am
Contact:

Re: Base64Decode....again

Post by FourthWorld » Thu Feb 12, 2015 5:59 pm

Thalor wrote:Interesting thing.

It all works. I can select an image. Put it into Image1, encode it and store it in MYSQL. I can retrieve it from MYSQL, decode and put it in Image2

HOWEVER

If Image1 and Image2 are different sizes (Height and Width) the image gets messed up

Any ideas?
I had thought that was the case too, but I found that when I delete image 2 and made a new one at a different size, it still works.

Still unable to reproduce the non-working state, though I did see it once so at least we know you're not imagining this. :)
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

Klaus
Posts: 14208
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Base64Decode....again

Post by Klaus » Thu Feb 12, 2015 6:09 pm

Hi all,
Using and setting imagedata requires that both images (source and target) have the SAME (sic!) dimensions (width and height)!
this is correct according to the dictionary, so why tempt fate unneccessarily? :D

If the two images do not have the same dimensions, or if you are no sure about this, then do not use the imagedata but:

Code: Select all

on mouseUp
   put base64encode(the TEXT of image "Image1") into field "text"
end mouseUp

Code: Select all

on mouseUp
   local decodedBinData
   put base64decode (field "text") into decodedBinData
   set the TEXT of img "Image2" to decodedBinData 
end mouseUp
I have to confess that "the TEXT of IMAGE..." is a bit mentally challenging to me :D


Best

Klaus

Thierry
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 875
Joined: Wed Nov 22, 2006 3:42 pm

Re: Base64Decode....again

Post by Thierry » Thu Feb 12, 2015 6:11 pm

Thalor wrote: If Image1 and Image2 are different sizes (Height and Width) the image gets messed up
Any ideas?
In your first Post, you are reading and encoding the imageData,
and then setting back the image, but not the imageData!

Are you still doing this?
!
SUNNY-TDZ.COM doesn't belong to me since 2021.
To contact me, use the Private messages. Merci.
!

Klaus
Posts: 14208
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Base64Decode....again

Post by Klaus » Thu Feb 12, 2015 6:19 pm

Bonjour Thierry,

I think we already solved this :D


Best

Klaus

Thierry
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 875
Joined: Wed Nov 22, 2006 3:42 pm

Re: Base64Decode....again

Post by Thierry » Thu Feb 12, 2015 6:26 pm

Klaus wrote: I think we already solved this :D
I didn't see your answer when typing mine,
you were faster :roll:

Best,

Thierry
!
SUNNY-TDZ.COM doesn't belong to me since 2021.
To contact me, use the Private messages. Merci.
!

Klaus
Posts: 14208
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Base64Decode....again

Post by Klaus » Thu Feb 12, 2015 6:35 pm

You needed almost one hour for typing this? :shock:

:D

Thierry
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 875
Joined: Wed Nov 22, 2006 3:42 pm

Re: Base64Decode....again

Post by Thierry » Thu Feb 12, 2015 6:40 pm

Klaus wrote:You needed almost one hour for typing this? :shock:
It's winter here :)

But more seriously, somehow missed your 1st post.
Sorry about that...
!
SUNNY-TDZ.COM doesn't belong to me since 2021.
To contact me, use the Private messages. Merci.
!

Thalor
Posts: 6
Joined: Thu Feb 12, 2015 4:35 pm

Re: Base64Decode....again

Post by Thalor » Thu Feb 12, 2015 6:45 pm

Thanks to all who helped. This has put me on the right path.

Thanks again!

Klaus
Posts: 14208
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Base64Decode....again

Post by Klaus » Thu Feb 12, 2015 6:48 pm

Thierry wrote:
Klaus wrote:You needed almost one hour for typing this? :shock:
It's winter here :)
Ah, OK, that explains it :D
Thierry wrote:Sorry about that...
Hey, really no need for excuses, mon ami!
I just love joking around a bit :D

Post Reply