• 0

Display the picture in [object HTMLImageElement] using PHP


Question

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.

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.

The library is this one BTW: http://www.nihilogic.dk/labs/canvas2image/

I need to get the string that is useable in a normal

<img src="">

How can I do this?

Thanks

5 answers to this question

Recommended Posts

  • 0

You'd have to use toDataURL to convert the image data into a string (I assume you're actually trying to store a reference to the DOM element, hence why PHP is seeing the result of the JavaScript toString call)

But it probably won't work well, cookies have a limit of 4096 bytes or so, and you can only store a certain amount of cookies per domain/page, so you'd have to split the image into multiple parts (quite possibly stopping mid way through). If you need the server to access the image, POSTing it would be much better (No effective limit here)

  • 0
  On 09/05/2012 at 11:12, The_Decryptor said:

You'd have to use toDataURL to convert the image data into a string (I assume you're actually trying to store a reference to the DOM element, hence why PHP is seeing the result of the JavaScript toString call)

But it probably won't work well, cookies have a limit of 4096 bytes or so, and you can only store a certain amount of cookies per domain/page, so you'd have to split the image into multiple parts (quite possibly stopping mid way through). If you need the server to access the image, POSTing it would be much better (No effective limit here)

Damn :(

This was the only possible way.

I make this via a Lightbox window (which is JS anyways but for the point being), that "window" closes, then later I click a link and THEN I display it. Thats why this method was perfect for the situation at hand.

  • 0

Ive been able to do with a form and a hidden input box but I cant pass it to another page....

This is the code I have

&lt;form id="imagen" method="post" name="imagen" action="#"&gt;
Con Corte - A?adir carro
&lt;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"&gt;
&lt;/form&gt;

Explaining 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 (the action)) 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.

I hope this can give me some other way to do it :) So please, some help! Thank you!

  • 0

Ive basically worked it down to this:

My JS:

$j(textoDelId, window.parent.document).html(Add&lt;input id="imagenv" name="imagenv" value="'+imgstr+'" type="hidden"&gt;');		
[/CODE]

My new submit button:
[code]&lt;form id="imagen" method="post" name="imagen" action="javascript:void(0);"&gt;&lt;button id="&lt;?php echo $idBotonCarritoCustom ?&gt;" class="button btn-cart" title="&lt;?php echo $this-&gt;__('Add to Cart') ?&gt;" onclick="mandarAlCarro('&lt;?php echo $this-&gt;getAddToCartUrl($_product) ?&gt;',                            &lt;?php $idOptionCorte = -1; foreach ($_product-&gt;getProductOptionsCollection() as $option) {                            if($option-&gt;getTitle() == 'Corte') {                                $idOptionCorte = $option-&gt;getOptionId();                            }}                                echo $idOptionCorte?&gt;, &lt;?php echo $_product-&gt;_getData('entity_id'); ?&gt;)" type="submit"&gt;
                            &lt;span&gt;&lt;span&gt;&lt;?php echo $this-&gt;__('Add to Cart') ?&gt;&lt;/span&gt;&lt;/span&gt;&lt;/button&gt;&lt;/form&gt;

and last the destination:

 &lt;?php echo $_POST["imagenv"]; ?&gt;

imgstr has the correct value as I do a alert after the JS line and it shows it correctly.

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.