Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Worked on image editing toolkit #11

Merged
merged 1 commit into from
Jul 16, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
worked on image editing toolkit
Saga690 committed Jul 16, 2024
commit e8169c603ae8d3ea1e4e3f674f90a44f67593831
46 changes: 46 additions & 0 deletions Day 2/Issue 8/Saga/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Image Editor</title>
<link rel="stylesheet" href="main.css">
<script src="main.js"></script>
</head>

<body>
<div class="editor">
<div class="options">
<div class="item">
<label for="image-input">Insert file here:</label>
<input type="file" id="image-input">
</div>
<div class="item">
<label for="brightness">Brightness:</label>
<input type="range" id="brightness" min="0" max="200">
</div>
<div class="item">
<label for="contrast">Contrast:</label>
<input type="range" id="contrast" min="0" max="200">
</div>
<div class="item">
<label for="inversion">Inversion:</label>
<input type="range" id="inversion" min="0" max="100">
</div>
<div class="item">
<label for="saturation">Saturation:</label>
<input type="range" id="saturation" min="0" max="200">
</div>
<div class="item">
<label for="blur">Blur:</label>
<input type="range" id="blur" min="0" max="25">
</div>
</div>
<div class="image">
<canvas height="500" width="500" id="canvas"></canvas>
</div>
</div>
</body>

</html>
146 changes: 146 additions & 0 deletions Day 2/Issue 8/Saga/main.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
@import url('https://fonts.googleapis.com/css2?family=Playwrite+HU:wght@100..400&display=swap');

* {
margin: 0;
font-family: "Playwrite HU", cursive;
}

.editor {
display: flex;
width: 100vw;
height: 100vh;
}

.options {
width: 250px;
background-color: green;
display: flex;
flex-direction: column;
justify-content: space-around;
color: white;
}

.item {
padding: 15px;
}

.item label {
display: block;
margin-bottom: 5px;
font-size: 14px;
font-weight: bold;
font-size: 18px;
margin-bottom: 10px;
letter-spacing: 0.8px;
}

.item input {
width: 100%;
}


.image {
flex-grow: 1;
padding: 20px;
/* background-color: rgb(188, 188, 188); */
background-color: lightgray;
}

.image canvas {
max-width: 100%;
max-height: 100%;
}

input[type=range] {
-webkit-appearance: none;
width: 100%;
background: transparent;
}

input[type=range]::-webkit-slider-thumb {
-webkit-appearance: none;
}

input[type=range]:focus {
outline: none;
}

input[type=range]::-ms-track {
width: 100%;
cursor: pointer;

/* Hides the slider so custom styles can be added */
background: transparent;
border-color: transparent;
color: transparent;
}

input[type=range]::-webkit-slider-thumb {
-webkit-appearance: none;
border: 1px solid #000000;
height: 36px;
width: 16px;
border-radius: 3px;
background: #ffffff;
cursor: pointer;
margin-top: -14px;
box-shadow: 1px 1px 1px #000000, 0px 0px 1px #0d0d0d;
}


input[type=range]::-ms-thumb {
box-shadow: 1px 1px 1px #000000, 0px 0px 1px #0d0d0d;
border: 1px solid #000000;
height: 36px;
width: 16px;
border-radius: 3px;
background: #ffffff;
cursor: pointer;
}

input[type=range]::-webkit-slider-runnable-track {
width: 100%;
height: 8.4px;
cursor: pointer;
box-shadow: 1px 1px 1px #000000, 0px 0px 1px #0d0d0d;
background: #3071a9;
border-radius: 1.3px;
border: 0.2px solid #010101;
}

input[type=range]:focus::-webkit-slider-runnable-track {
background: #367ebd;
}


input[type=range]::-ms-track {
width: 100%;
height: 8.4px;
cursor: pointer;
background: transparent;
border-color: transparent;
border-width: 16px 0;
color: transparent;
}

input[type=range]::-ms-fill-lower {
background: #ffffff;
border: 0.2px solid #010101;
border-radius: 2.6px;
box-shadow: 1px 1px 1px #000000, 0px 0px 1px #0d0d0d;
}

input[type=range]:focus::-ms-fill-lower {
background: #3071a9;
}

input[type=range]::-ms-fill-upper {
background: #3071a9;
border: 0.2px solid #010101;
border-radius: 2.6px;
box-shadow: 1px 1px 1px #000000, 0px 0px 1px #0d0d0d;
}

input[type=range]:focus::-ms-fill-upper {
background: #367ebd;
}
69 changes: 69 additions & 0 deletions Day 2/Issue 8/Saga/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
document.addEventListener('DOMContentLoaded', () => {

const fileInput = document.querySelector('#image-input');
const canvas = document.querySelector('#canvas');
const canvasCtx = canvas.getContext("2d");
const brightnessInput = document.querySelector('#brightness');
const contrastInput = document.querySelector('#contrast');
const inversionInput = document.querySelector('#inversion');
const saturationInput = document.querySelector('#saturation');
const blurInput = document.querySelector('#blur');

const settings = {};
let image = null;

function resetSettings() {
settings.brightness = "100";
settings.contrast = "100";
settings.inversion = "0";
settings.saturation = "100";
settings.blur = "0";

brightnessInput.value = settings.brightness;
contrastInput.value = settings.contrast;
inversionInput.value = settings.inversion;
saturationInput.value = settings.saturation;
blurInput.value = settings.blur;
}

function updateSettings(key, value) {
if (!image) return;

settings[key] = value;
renderImage();
}

function generateFilter() {
const { brightness, contrast, inversion, saturation, blur } = settings;

return `brightness(${brightness}%) contrast(${contrast}%) invert(${inversion}%) saturate(${saturation}%) blur(${blur}px)`
}

function renderImage() {
canvas.width = image.width;
canvas.height = image.height;

canvasCtx.filter = generateFilter();
canvasCtx.drawImage(image, 0, 0);
}

brightnessInput.addEventListener("change", () => { updateSettings("brightness", brightnessInput.value) });
contrastInput.addEventListener("change", () => { updateSettings("contrast", contrastInput.value) });
inversionInput.addEventListener("change", () => { updateSettings("inversion", inversionInput.value) });
saturationInput.addEventListener("change", () => { updateSettings("saturation", saturationInput.value) });
blurInput.addEventListener("change", () => { updateSettings("blur", blurInput.value) });

fileInput.addEventListener("change", () => {
image = new Image();

image.addEventListener("load", () => {
resetSettings();
renderImage();
});

image.src = URL.createObjectURL(fileInput.files[0]);

})

resetSettings();
});
Binary file added Day 2/Issue 8/Saga/screenshots/edited.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Day 2/Issue 8/Saga/screenshots/unedited.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.