Mobile phones
Online Photo Editor
CSS Code:
css
Copy code
* {
box-sizing: border-box;
margin: 0;
padding: 0;
}
.container {
max-width: 800px;
margin: 0 auto;
padding: 1rem;
}
header {
text-align: center;
margin-bottom: 1rem;
}
canvas {
max-width: 100%;
height: auto;
display: block;
}
.tools {
display: flex;
justify-content: space-between;
margin-bottom: 1rem;
}
.tools button {
padding: 0.5rem 1rem;
font-size: 1rem;
background-color: #4caf50;
color: white;
border: none;
border-radius: 0.25rem;
cursor: pointer;
}
.tools button:hover {
background-color: #3e8e41;
}
footer {
text-align: center;
margin-top: 1rem;
}
JS Code:
javascript
Copy code
const canvas = document.getElementById('canvas');
const ctx = canvas.getContext('2d');
let img = new Image();
let imgData;
// Load image on canvas
function loadImage(src) {
img.onload = function () {
canvas.width = img.width;
canvas.height = img.height;
ctx.drawImage(img, 0, 0);
imgData = ctx.getImageData(0, 0, canvas.width, canvas.height);
};
img.src = src;
}
// Upload image
const btnUpload = document.getElementById('btn-upload');
btnUpload.addEventListener('click', function () {
const input = document.createElement('input');
input.type = 'file';
input.accept = 'image/*';
input.addEventListener('change', function () {
const file = this.files[0];
const reader = new FileReader();
reader.onload = function () {
loadImage(reader.result);
};
reader.readAsDataURL(file);
});
input.click();
});
// Save image
const btnSave = document.getElementById('btn-save');
btnSave.addEventListener('click', function () {
const link = document.createElement('a');
link.download = 'edited-image.png';
link.href = canvas.toDataURL();
link.click();
});
// Reset changes
const btnReset = document.getElementById('btn-reset');
btnReset.addEventListener('click
Send a message.
Free screen recorder tool
Screen Recorder Start Recording Stop Recording
Comments
Post a Comment
sunil191280@gmail.com