Categories
JavaScript Answers

How to merge image using JavaScript?

Spread the love

Sometimes, we want to merge image using JavaScript.

In this article, we’ll look at how to merge image using JavaScript.

How to merge image using JavaScript?

To merge image using JavaScript, we use the merge-images package.

To install it, we run

npm i merge-images

Then we use it by writing

import mergeImages from "merge-images";

const b64 = await mergeImages(["/body.png", "/eyes.png", "/mouth.png"]);
document.querySelector("img").src = b64;

to call mergeImages to return a promise that merges the images at the paths in the array.

Then we get the b64 base64 image URL string from the returned promise and assign that as the value of the src attribute of an img element.

Conclusion

To merge image using JavaScript, we use the merge-images package.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *