Home > Article > Web Front-end > How to Convert Base64 to an Image in JavaScript?
In your code, item_image holds the base64-encoded image data. To convert this data to an image, follow these steps:
<code class="javascript">var image = new Image();</code>
<code class="javascript">image.src = 'data:image/png;base64,' + item_image;</code>
This line sets the src property of the image object to the base64-encoded data, including the necessary header indicating the image's data type (data:image/png).
<code class="javascript">document.body.appendChild(image);</code>
This appends the image object to the HTML document, allowing it to be displayed.
The above is the detailed content of How to Convert Base64 to an Image in JavaScript?. For more information, please follow other related articles on the PHP Chinese website!