Logo

dev-resources.site

for different kinds of informations.

Binary Image Processor

Published at
9/3/2024
Categories
javascript
image
html
css
Author
himanshi58158
Categories
4 categories in total
javascript
open
image
open
html
open
css
open
Author
13 person written this
himanshi58158
open
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:

  1. file upload
  2. binary manipulation
  3. image preview
  4. 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>`

## 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);
Enter fullscreen mode Exit fullscreen mode

}
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);
Enter fullscreen mode Exit fullscreen mode

}
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);
Enter fullscreen mode Exit fullscreen mode

}
`

The output for this is shown below:

Image description

image Article's
30 articles in total
Favicon
Transforming AI with Image Datasets for Machine Learning
Favicon
How to apply Image optimization For Your Website
Favicon
Understanding Image Data Representation in Computer Systems
Favicon
AI Image Validation Solutions: A Game-Changer for Quality Control
Favicon
AVIF File Format: The Evolution in Web Image Compression
Favicon
Lightweight, Transparent, Animated: Get All of Them by WebP Format
Favicon
Making a simple pointillism painting using OpenCv.
Favicon
Top Image to HTML Converter Comparison
Favicon
How I.T Dolphins Ensures Customer Satisfaction
Favicon
Flutter Image Compression: Ensuring High Quality
Favicon
Binary Image Processor
Favicon
Face image dataset
Favicon
Image search with Streamlit in Snowflake (SiS) Part 1 - Creating an image gallery app -
Favicon
🌟 Introducing Universal Image Component: The Ultimate React/NextJS Image Solution! 📸
Favicon
The Art of Image Uploads: Why Storing File Names Alone Won't Cut It
Favicon
I want to improve design and functionality of Image Color Picker?
Favicon
Free Image hosting solution for your website
Favicon
Professional Free Image Hosting Platform: Pics Shade
Favicon
Detailed Explanation of LangChain
Favicon
Japanese standard stock photos
Favicon
From Oven to Table: Stylish Baking Trays That Double as Serving Platters
Favicon
Overview of Fundamentals in Image Science
Favicon
Unleash Your Inner Chef: Exploring the World of Professional Pizza Pans
Favicon
Crafting Culinary Perfection: The Art of Baking Tray Selection
Favicon
Baking Essentials: Must-Have Baking Trays Every Home Cook Should Own
Favicon
Cake Baking 101: Choosing the Right Cake Pan for Every Occasion
Favicon
Small spacing LEDs are more suitable for command centers
Favicon
Understanding DiT (Diffusion Transformer) in One Article
Favicon
Image Effects With HTML Canvas
Favicon
Retrieval-Augmented Generation (RAG) Technology Guide

Featured ones: