Display the picture in [object HTMLImageElement] using PHP
Hey
I tried to access a cookie that has a [object HTMLImageElement] but when I try to echo it, it simply prints that out: [object HTMLImageElement] I want it to display the picture.
How can I do this?
Thanks
11 Months Ago
Last Updated
riahc3
1,282 posts since May 2008
Reputation Points: 62
Solved Threads: 13
Skill Endorsements: 11
I'm currently at a break so in a few mintues, ill post some more code.
I used a canvas2image JS library, in Javascript, I was able to generate the image and display it but I want to save the html code in a cookie and just display it.
riahc3
1,282 posts since May 2008
Reputation Points: 62
Solved Threads: 13
Skill Endorsements: 11
In Javascript:
var canvas=document.getElementById("can");
var ojpeg=Canvas2Image.saveAsPNG(canvas,true,100,100);
document.cookie ='laimagen='+ojpeg+'; expires='+dia.toGMTString()+'; path=/';
var imgHtml = ojpeg;
alert (imgHtml);
Alert pops up with [object HTMLImageElement] and I need to put valid HTML so I can use it in PHP.....
riahc3
1,282 posts since May 2008
Reputation Points: 62
Solved Threads: 13
Skill Endorsements: 11
riahc3
1,282 posts since May 2008
Reputation Points: 62
Solved Threads: 13
Skill Endorsements: 11
(The quoting system here is horrible)
Is this demo code from the library of canvas2image? I couldnt find it on the site.
riahc3
1,282 posts since May 2008
Reputation Points: 62
Solved Threads: 13
Skill Endorsements: 11
Putting
canvas.toDataURL("image/png");
in my code (with var canvas=document.getElementById("can"); before it) prints out the same thing. [object HTMLImageElement]
riahc3
1,282 posts since May 2008
Reputation Points: 62
Solved Threads: 13
Skill Endorsements: 11
I dont have to display it either; As long as I can get the string to put it in a
<img src
Im fine....
riahc3
1,282 posts since May 2008
Reputation Points: 62
Solved Threads: 13
Skill Endorsements: 11
I ahve created demo code again :) Try now:
Thanks a lot for the code :) I really appritiate it :)
The problem is, i already have a canvas and I can already draw on it. What i simply want to do is make a "screenshot" of it and transport that screenshot else where. The "hidden form" from what is seems is what you are suggesting to do so I can transport it elsewhere right?
riahc3
1,282 posts since May 2008
Reputation Points: 62
Solved Threads: 13
Skill Endorsements: 11
document.getElementById('myImg').src = getCookie('myImage');
With that, there is a possibility I can store than in the cookie right?
riahc3
1,282 posts since May 2008
Reputation Points: 62
Solved Threads: 13
Skill Endorsements: 11
Did it worked?? Make thread solved if it is..
Im still not clear with your code as you are drawing and I can already draw.
None the less, Im trying with the second method you posted which is a hidden field. I can perfectly store the value in the value field of my hidden input box but when trying to access it via PHP via POST it is like it doesnt exist. I have some doubts of the reason why.
My code is basically:
<form id="imagen" method="post" name="imagen" action="#">
Con Corte - Añadir carro
<input id="imagen" type="hidden" value="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAGQAAABkCAYAAABw4pVUAAACIklEQVR4nO3bz4tNYRzH8fcY5MewENJQUoOyJEnKKKnZsaAsyGJK+AOsb1NYStn4kZLYkI2oWfnTjoWROUkzc+8553Oec9+v3V3c57xvzzl17r3fA5IkSZIkSZIkSZIkSZIkqWdGVIyogHlgFbgLnNjgXUeAG8APYFu7gdNjGVhatyGT2g08bGCdqfKWbs7omx0co1j3Y0e+xuOGrr5BeJMOYIXFtQ15l05JepkO+I9L6YCuzdH/O57ZdEBXPqYDtmguHdCmi+mAMe1JB7ThQDpAf51PBzRgRzpgciN+Duze/lY6YDLD2xCA5+mASRR+RqkU19MB47iaDmhZcbfCT9IBLTueDtC/9qUDVPcoHSD13u10gOoW0wEq1FI6QHWv0wEdOpkO2IxT6YAOLacDVFfMpMqudEBHVtMBm5Wft+rG93SA6or+02pYmhsA78zXdECrCtyQvk8oTqWD6YAWzacDxjHkL07v0wEaiE/pgBY8SAeorvhHFu6kAxo0pM+iPrmcDmjAvXRAk0qfZSpyjHQjp9MBqiv+7mSIjqYDtmh7OqBth9IBW7AzHdCVIqY1pkmff5pfSAdkjKhY6d045pd0QM6IirN8SGesmQH2piP6YobsQ6Kfg8futVngTIfH80fCTdoPXGhx/Vf8vio1hhcNrTMPPGtoLQGHgW9/XlRQVWw4gvMUuNJmlNas25AF4BxwLJwkSZIkSZIkSZIkSSrfL4jkPrc69QHbAAAAAElFTkSuQmCC" name="imagen">
</form>
Now, you may be wondering about my action; This already does link me (this code is actually inside a button with a onclick action that leads me somewhere else so like I mentioned it is not needed) to somewhere but in action I cant put a link because it is dynamically generated. Action AFAIK is mandatory so I just put that to try it to pass. For some reason in PHP (with a simply <?php echo $_POST[imagen]; ?> I cannot get it to show. It just shows up blank.
As you can see, in value the data is perfectly there but I cannot pass it to another page.
Thanks for all the help!
riahc3
1,282 posts since May 2008
Reputation Points: 62
Solved Threads: 13
Skill Endorsements: 11
I did it to make sure it passes...........
Ill try rename the input field then.
riahc3
1,282 posts since May 2008
Reputation Points: 62
Solved Threads: 13
Skill Endorsements: 11
Still nothing.......does not pass the value.
riahc3
1,282 posts since May 2008
Reputation Points: 62
Solved Threads: 13
Skill Endorsements: 11
New code:
<form id="imagen" method="post" name="imagen" action="#">
Con Corte - Añadir carro
<input id="imagenv" type="hidden" value="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAGQAAABkCAYAAABw4pVUAAACA0lEQVR4nO3cwUsUYRzG8UdhKa0oEREpCjoUSOlJgiAWIbp26FZQt+iS2CH0ImwGXj2IWiePhnSo6L5/2nQoqFmVRvd93+edfb+f8/B7vzDsLDvzzkoAAAAAAAAAAAAAAAAAAPxrU11tquvOwG8P1VOlnipJHyR9dAeV6rDBMfvRKyBJmjzj8QdRKjC0BXfAqOkEmLERYAYkvQ0466KksYDzinMn0tzxSHMxhNvugLbZSbBGrE8ghjDnDmiDp+4AAANm3QG5emNc+7NxbZzinjsgJ4vuANS9cAf88dwdgONuuQPcrrkDBhR/E3LFHXCCLXcAICnvy4Pzd5FNjperos27A/7jujsAdQ/cASjYd3dAQ8vugFTuugMaeuUOQIFCbIBL4+/G7pH2zh3QWCEn5LE74Ix23QGo++QOQN2qOyCml+6Ac3jtDoijvV+Q6+6AONp7Qr64A2KacgecQ8h3VbJzwR0AAKNrzx2Aupw3YhSn+F2MubnpDkhhwh3Q0CV3QCpt2VpzxR2QypI7oIFtd0BKI30ru41+uANQl/O1Obd3VYp2wx2AnvrqqS/pqjvF7Zs7QFKbH5gFl8P/Vh25A3LzyLRuRzwky8aaOyBrlVRVSnIN/5pgjfaLfEI6kp5Eml2EZwFmTIs7AcG9lzTT8NjLkn5Kuh8vBwAAAAAAAACAJn4Bse83Wq3XeMoAAAAASUVORK5CYII=" name="imagenv">
</form>
On the PHP page (which when I click on that link it leads me to there) I do this:
<?php echo $_POST["imagenv"]; ?>
riahc3
1,282 posts since May 2008
Reputation Points: 62
Solved Threads: 13
Skill Endorsements: 11