• 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

    • UI is slow but you prefer a slower UI to a snappier UI basically. Everyone is different.
    • XFX 9060 XT 16 GB is $349 on Amazon (shipped & sold by Amazon) https://www.amazon.com/dp/B0F8...p;previewDohDeal=1&th=1 People - never trust any neowin deals posted - they are the worst at seeking deals, and just want to peddle their own to make a quick buck. It's disgusting.
    • It's a grey market key - proceed at your own risk. It's baffling that neowin supports this shady stuff.
    • Arc 1.57.0 by Razvan Serea ARC browser is finally here for Windows, bringing its unique and modern approach to browsing. With a clean interface and a powerful sidebar, ARC makes managing tabs and organizing your workflow a breeze. You can group tabs, pin important pages, and quickly switch between work and personal spaces without clutter. It’s designed to be fast, customizable, and genuinely useful, making it more than just a browser—it’s a productivity tool. If you’re on Windows and want a fresh way to browse and stay organized, ARC is worth checking out. ARC browser key features: Split View: Work with multiple tabs side by side in a single window for efficient multitasking. Tab Grouping: Organize tabs into customizable groups for better workflow management. Pinned Tabs: Keep essential pages permanently accessible in the sidebar. Spaces: Create separate workspaces for different projects or personal use, reducing clutter. Sidebar Integration: Access bookmarks, notes, and tools directly from the sidebar for quick navigation. Customizable Themes: Personalize the browser’s appearance with themes and color schemes. Quick Search: Find tabs, history, or bookmarks instantly with a powerful search bar. Lightning-Fast Performance: Built for speed with optimized resource usage and minimal lag. Built-in Note-Taking: Jot down ideas or save snippets directly within the browser. Focus Mode: Hide distractions and focus on a single tab or task. Cross-Device Syncing: Seamlessly sync your data across multiple devices for a unified experience. Keyboard Shortcuts: Boost productivity with customizable shortcuts for common actions. AI-Powered Suggestions: Get smart recommendations for tabs, bookmarks, and workflows. Privacy Controls: Built-in tools for blocking trackers and managing cookies for enhanced security. Extensions Support: Compatible with popular browser extensions to extend functionality. Arc Browser 1.57.0 release notes: ''Thanks as always for using Arc. This week's release includes a bump to Chromium 137.0.7151.69, which patched three security vulnerabilities. Enjoy!'' Download: Arc Browser 1.57.0 | 1.9 MB (Freeware) View: Arc Browser Website | Screenshot Get alerted to all of our Software updates on Twitter at @NeowinSoftware
    • they put useless AI, new plastick sticker 8K and price +$80 for nothing
  • Recent Achievements

    • First Post
      Uranus_enjoyer earned a badge
      First Post
    • Week One Done
      Uranus_enjoyer earned a badge
      Week One Done
    • Week One Done
      jfam earned a badge
      Week One Done
    • First Post
      survivor303 earned a badge
      First Post
    • Week One Done
      CHUNWEI earned a badge
      Week One Done
  • Popular Contributors

    1. 1
      +primortal
      427
    2. 2
      +FloatingFatMan
      237
    3. 3
      ATLien_0
      213
    4. 4
      snowy owl
      207
    5. 5
      Xenon
      159
  • Tell a friend

    Love Neowin? Tell a friend!