• 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.
  • Posts

    • Is there a 'recovery' settings option in Settings? The one where we can rollback to a previous restore point. I find it very useful if there is some issue and I have to rollback to the last stable point.
    • Google brings Gemini to all Workspace for Education subscribers by David Uzondu Google has announced that its Gemini app is now accessible to all Google Workspace for Education users, regardless of age. This brings the company's generative AI directly into the suite of tools used by millions of students and teachers. The Workspace for Education platform, if you did not know, already provides a massive suite of tools like Classroom, Docs, and Drive, which are designed to work together in a school setting. Naturally, the first question on any administrator's mind is what the company plans to do with student data. Google states that Gemini usage for these accounts falls under the Workspace for Education Terms of Service. This agreement includes "enterprise-grade data protections" and a promise that user data is not reviewed by anyone or used to train the company's AI models. It also maintains compliance with regulations like FERPA and COPPA, which are fundamental requirements for any technology operating in United States schools. The experience is not one-size-fits-all, particularly for younger students. Users under the age of 18 will get a more restricted version of the app, with stricter content filters to prevent inappropriate responses and a dedicated onboarding process to teach AI literacy. To reduce the likelihood of hallucinations, the first time a younger user asks a fact-based question, a double-check feature that validates the answer using Google Search runs automatically. For educators and older students, the AI can be used to brainstorm ideas, create lesson plans, and get feedback on work. The entire service is powered by what Google calls LearnLM, a family of its AI models supposedly fine-tuned for educational purposes. Access is not mandatory, as administrators can still control which users or groups can use the Gemini app through their admin console. This rollout applies to institutions using the free Education Fundamentals, the security-focused Standard, and the feature-rich Plus editions, making it widely available immediately.
    • Is it a bird? Is it a plane? No! It's a f-ing bomb!! This is why real rocket scientists don't base their designs on 1930's Flash Gordon comics...  
  • Recent Achievements

    • Contributor
      GravityDead went up a rank
      Contributor
    • Week One Done
      BlakeBringer earned a badge
      Week One Done
    • Week One Done
      Helen Shafer earned a badge
      Week One Done
    • First Post
      emptyother earned a badge
      First Post
    • Week One Done
      Crunchy6 earned a badge
      Week One Done
  • Popular Contributors

    1. 1
      +primortal
      661
    2. 2
      ATLien_0
      269
    3. 3
      Michael Scrip
      236
    4. 4
      Steven P.
      164
    5. 5
      +FloatingFatMan
      151
  • Tell a friend

    Love Neowin? Tell a friend!