Home > Web Front-end > JS Tutorial > How to Convert Base64 to Image in JavaScript/jQuery?

How to Convert Base64 to Image in JavaScript/jQuery?

Patricia Arquette
Release: 2024-10-28 20:40:31
Original
692 people have browsed it

How to Convert Base64 to Image in JavaScript/jQuery?

How to Convert Base64 to Image in JavaScript/jQuery

You have encountered a task where you need to convert captured base64 data from a camera feed into an image. Here's how you can accomplish this in JavaScript/jQuery:

To convert the base64 data into an image:

<code class="javascript">var image = new Image();
image.src = 'data:image/png;base64,' + item_image;</code>
Copy after login

The above code creates an Image object and sets its source (src) to the base64 data you have, including the 'data:image/png;base64,' part.

Once the image is loaded, you can append it to the DOM using:

<code class="javascript">document.body.appendChild(image);</code>
Copy after login

This will display the image in your HTML document.

It's important to note that some browsers might not support data URIs. You can check the [compatibility table](link to table) for more information.

The above is the detailed content of How to Convert Base64 to Image in JavaScript/jQuery?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template