Binary Image Processor
let's create a
Binary Image Processor.
Project Overview:
Create a web application that allows users to upload an image, manipulate the binary data of the image, and then save the modified image. The app will enable users to apply various effects like grayscale, inversion, and brightness adjustment by directly modifying the image’s binary data.
key features:
- file upload
- binary manipulation
- image preview
- download image option
we'll be using HTML,CSS, AND JAVASCRIPT
html:
`>
Binary Image Processor
<input type="file" name="" id="fileinput" accept="image/*"> <br> <button id="grayscalebtn">Apply GrayScale</button> <button id="invertbtn">Apply Inversion</button> <button id="brightnessbtn">Apply Brightness</button> <input type="range" name="" id="brightnessrange" min="-100" max="100" value="0"> <br> <canvas id="canvas"></canvas> <br> <button id="downloadbtn">Download Image</button>`Copy after login
## css:
*{
background-color: rgb(160, 226, 204);
}
body {
font-family: Arial, sans-serif;
text-align: center;
padding: 20px;
}
#canvas {
border: 1px solid #000;
margin-top: 20px;
}
**
javascript:
**
`document.getElementById('grayscalebtn').addEventListener('click', applyGrayscale);
document.getElementById('invertbtn').addEventListener('click', applyInversion);
const brightnessRange = document.getElementById('brightnessbtn');
brightnessRange.addEventListener('input', () => {
ctx.putImageData(originalImageData, 0, 0); // Reset to original before applying brightness
adjustBrightness(Number(brightnessRange.value));
});
document.getElementById('downloadbtn').addEventListener('click', () => {
const link = document.createElement('a');
link.download = 'modified-image.png';
link.href = canvas.toDataURL();
link.click();
});
const fileinput = document.getElementById('fileinput'); const canvas = document.getElementById('canvas'); const ctx = canvas.getContext('2d'); let originalImageData; fileinput.addEventListener('change',(event)=>{ const file = event.target.files[0]; const reader = new FileReader(); reader.onload = function(e){ const img = new Image(); img.onload = function(){ canvas.width = img.width; canvas.height = img.height; ctx.drawImage(img,0,0); originalImageData = ctx.getImageData(0,0,canvas.width,canvas.height); } img.src = e.target.result; } reader.readAsDataURL(file); }) function applyGrayscale() { let imageData = ctx.getImageData(0, 0, canvas.width, canvas.height); let data = imageData.data; for (let i = 0; i < data.length; i += 4) { const r = data[i]; const g = data[i + 1]; const b = data[i + 2]; const grayscale = r * 0.3 + g * 0.59 + b * 0.11; data[i] = data[i + 1] = data[i + 2] = grayscale; } ctx.putImageData(imageData, 0, 0);
}
function applyInversion() {
let imageData = ctx.getImageData(0, 0, canvas.width, canvas.height);
let data = imageData.data;
for (let i = 0; i < data.length; i += 4) { data[i] = 255 - data[i]; // Red data[i + 1] = 255 - data[i + 1]; // Green data[i + 2] = 255 - data[i + 2]; // Blue } ctx.putImageData(imageData, 0, 0);
}
function adjustBrightness(value) {
let imageData = ctx.getImageData(0, 0, canvas.width, canvas.height);
let data = imageData.data;
for (let i = 0; i < data.length; i += 4) { data[i] += value; // Red data[i + 1] += value; // Green data[i + 2] += value; // Blue } ctx.putImageData(imageData, 0, 0);
}
`
The output for this is shown below:
The above is the detailed content of Binary Image Processor. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

It's out! Congrats to the Vue team for getting it done, I know it was a massive effort and a long time coming. All new docs, as well.

With the recent climb of Bitcoin’s price over 20k $USD, and to it recently breaking 30k, I thought it’s worth taking a deep dive back into creating Ethereum

I had someone write in with this very legit question. Lea just blogged about how you can get valid CSS properties themselves from the browser. That's like this.

The other day, I spotted this particularly lovely bit from Corey Ginnivan’s website where a collection of cards stack on top of one another as you scroll.

I'd say "website" fits better than "mobile app" but I like this framing from Max Lynch:

There are a number of these desktop apps where the goal is showing your site at different dimensions all at the same time. So you can, for example, be writing

If we need to show documentation to the user directly in the WordPress editor, what is the best way to do it?

Questions about purple slash areas in Flex layouts When using Flex layouts, you may encounter some confusing phenomena, such as in the developer tools (d...
