- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Combining multiple images into a single one using JavaScript
Following is the code for combining multiple images into a single one using JavaScript −
Example
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <title>Document</title> <style> body { font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif; } </style> </head> <body> <h1>Combining multiple images into a single one</h1> <img class="image" src="https://i.picsum.photos/id/845/250/250.jpg?hmac=2l7QArh4UKul2qF-JvTjaBu3-WF2KpKBgpBALmFoxWY"/> <img class="image" src="https://i.picsum.photos/id/925/250/250.jpg?hmac=twWJdaKT46cPk1aNvB7aKdiLZoQ zvzu5VW85OEUO4ys"/> <canvas class="result"></canvas> <br /> <button class="Btn">CLICK HERE</button> <h3>Click on the above button to combine the two images above together</h3> <script> let imgEle1 = document.querySelectorAll(".image")[0]; let imgEle2 = document.querySelectorAll(".image")[1]; let resEle = document.querySelector(".result"); var context = resEle.getContext("2d"); let BtnEle = document.querySelector(".Btn"); BtnEle.addEventListener("click", () => { resEle.width = imgEle1.width; resEle.height = imgEle1.height; context.globalAlpha = 1.0; context.drawImage(imgEle1, 0, 0); context.globalAlpha = 0.5; context.drawImage(imgEle2, 0, 0); }); </script> </body> </html>
Output
On clicking the ‘CLICK HERE’ button −
- Related Articles
- Combine multiple images using one dockerfile
- Combining multiple rows into a comma delimited list in MySQL?
- JavaScript: Combine highest key values of multiple arrays into a single array
- Plot multiple time-series DataFrames into a single plot using Pandas (Matplotlib)
- Inserting multiple parameter values into a single column with MySQL?
- How to show multiple images in one figure in Matplotlib?
- How to Merge multiple CSV Files into a single Pandas dataframe ?
- Convert a list of multiple integers into a single integer in Python
- Combining two Series into a DataFrame in Pandas
- How to display multiple images in one figure correctly in matplotlib?
- How can we insert multiple tabs into a single JTabbedPane in Java?
- Join Map values into a single string with JavaScript?
- How to save multiple plots into a single HTML file in Python Plotly?
- Converting images to a Base64 data URL using Javascript
- Excel Tutorial: Combine Multiple Workbooks/Worksheets into One

Advertisements