Home >Web Front-end >JS Tutorial >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>
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>
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!