Skip to content

Commit 95a20f2

Browse files
committed
separated functions and enabled button upon file load
1 parent d9a7c38 commit 95a20f2

File tree

12 files changed

+89
-73
lines changed

12 files changed

+89
-73
lines changed

README.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# Image Editor Online
22

3-
Powerfully edit and export images online. Powered by the CSS 2.1 filter property
3+
Powerfully edit and export images online. Powered by the CSS 2.1 filter property.
4+
5+
_why don't you star it too?✨_
46

57
## Technologies Used
68

@@ -15,6 +17,7 @@ Powerfully edit and export images online. Powered by the CSS 2.1 filter property
1517
- Cloudflare Pages → Hosting
1618
- Git → Version Control
1719
- GitHub → Source Control
20+
- Visual Studio Code → Code Editor
1821

1922
## Clone Repository
2023

@@ -41,6 +44,10 @@ In the terminal...
4144
or
4245
- Type `tsc -w` for continuous compilation.
4346

47+
## How to Contribute
48+
49+
If you'd like to help the development of this project, I will constantly be leaving comments on the code with what needs to be fixed.
50+
4451
## License
4552

4653
- [MIT License](https://mit-license.org/)

dist/Download.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
"use strict";
2+
const Download = () => {
3+
const img = document.getElementById('output');
4+
const canvas = document.createElement('canvas');
5+
const ctx = canvas.getContext('2d');
6+
ctx.drawImage(img, 0, 0);
7+
ctx.filter = "brightness(200)";
8+
const dataURL = canvas.toDataURL('image/png');
9+
const link = document.createElement('a');
10+
link.download = 'output.png';
11+
link.href = dataURL;
12+
link.click();
13+
};

dist/Edit.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
"use strict";
2+
const Edit = () => {
3+
const img = document.getElementById('output');
4+
const sepia = parseFloat(document.querySelector('#sepia').value);
5+
const bright = parseFloat(document.querySelector('#brightness').value);
6+
const contrast = parseFloat(document.querySelector('#contrast').value);
7+
const grayscale = parseFloat(document.querySelector('#grayscale').value);
8+
const saturation = parseFloat(document.querySelector('#saturation').value);
9+
const hue = parseFloat(document.querySelector('#hue').value);
10+
img.style.filter = `sepia(${sepia}%) brightness(${bright}%) contrast(${contrast}%) grayscale(${grayscale}%) saturate(${saturation}%) hue-rotate(${hue}deg)`;
11+
};

dist/Reset.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
"use strict";
2+
document.querySelector('#reset-btn').addEventListener('click', () => {
3+
document.querySelector('#adjustments').reset();
4+
Edit();
5+
});

dist/index.js

Lines changed: 0 additions & 31 deletions
This file was deleted.

dist/loadFile.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
"use strict";
2+
const loadFile = (event) => {
3+
const image = document.querySelector('#output');
4+
image.src = URL.createObjectURL(event.target.files[0]);
5+
document.querySelector('#export-image-btn').disabled = false;
6+
Edit();
7+
};

index.html

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
<body>
2222
<div class="container-sm mt-4">
2323
<h1><i class="bi bi-card-image"></i> Online Image Editor</h1>
24-
<p>Edit images online with a variety of filters. Powered by the filter property present in CSS 3</p>
24+
<p>Edit images online with a variety of filters. Powered by the filter property present in CSS 2.1</p>
2525
<form class="my-4">
2626
<label for="formFile" class="form-label">Select an image or GIF to begin</label>
2727
<input class="form-control" accept="image/*" type="file" id="file" onchange="loadFile(event)">
@@ -50,9 +50,10 @@ <h1><i class="bi bi-card-image"></i> Online Image Editor</h1>
5050
<input type="range" class="form-range" id="sepia" default="0" value="0" oninput="Edit()" min="0">
5151

5252
<div class="text-center my-4">
53-
<button class="btn btn-outline-primary m-1" type="button" onclick="Download()"
54-
data-bs-toggle="tooltip" data-bs-placement="top" title="Download the edited image"><i
55-
class="bi bi-cloud-arrow-down"></i> Export Image</button>
53+
<button class="btn btn-outline-primary m-1" type="button" id="export-image-btn"
54+
onclick="Download()" disabled data-bs-toggle="tooltip" data-bs-placement="top"
55+
title="Download the edited image"><i class="bi bi-cloud-arrow-down"></i> Export
56+
Image</button>
5657
<button class="btn btn-outline-danger m-1" type="button" id="reset-btn" data-bs-toggle="tooltip"
5758
data-bs-placement="top" title="Reset the adjustments"><i class="bi bi-arrow-clockwise"></i>
5859
Reset Sliders</button>
@@ -69,7 +70,10 @@ <h1><i class="bi bi-card-image"></i> Online Image Editor</h1>
6970
rel="noopener">Source Code</a>, <a href="mailto:damian@dkatsios.tk">Contact</a>
7071
</div>
7172
</div>
72-
<script src="dist/index.js"></script>
73+
<script src="dist/loadFile.js"></script>
74+
<script src="dist/Edit.js"></script>
75+
<script src="dist/Reset.js"></script>
76+
<script src="dist/Download.js"></script>
7377
<script>
7478
var tooltipTriggerList = [].slice.call(document.querySelectorAll('[data-bs-toggle="tooltip"]'))
7579
var tooltipList = tooltipTriggerList.map(function (tooltipTriggerEl) {

src/Download.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
const Download = () => {
2+
const img: any = <HTMLImageElement>document.getElementById('output')!;
3+
const canvas: any = document.createElement('canvas');
4+
const ctx: any = canvas.getContext('2d');
5+
//crops and zooms the image a lot
6+
ctx.drawImage(img, 0, 0);
7+
//must apply the filters here
8+
ctx.filter = "brightness(200)";
9+
const dataURL: any = canvas.toDataURL('image/png');
10+
const link: any = document.createElement('a');
11+
link.download = 'output.png';
12+
link.href = dataURL;
13+
link.click();
14+
}

src/Edit.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
const Edit = () => {
2+
const img: any = <HTMLImageElement>document.getElementById('output')!;
3+
const sepia: number = parseFloat((<HTMLInputElement>document.querySelector('#sepia')).value)!;
4+
const bright: number = parseFloat((<HTMLInputElement>document.querySelector('#brightness')).value)!;
5+
const contrast: number = parseFloat((<HTMLInputElement>document.querySelector('#contrast')).value)!;
6+
const grayscale: number = parseFloat((<HTMLInputElement>document.querySelector('#grayscale')).value)!;
7+
const saturation: number = parseFloat((<HTMLInputElement>document.querySelector('#saturation')).value)!;
8+
const hue: number = parseFloat((<HTMLInputElement>document.querySelector('#hue')).value)!;
9+
img.style.filter = `sepia(${sepia}%) brightness(${bright}%) contrast(${contrast}%) grayscale(${grayscale}%) saturate(${saturation}%) hue-rotate(${hue}deg)`
10+
}

src/Reset.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
(<HTMLButtonElement>document.querySelector('#reset-btn')).addEventListener('click', () => {
2+
(<HTMLFormElement>document.querySelector('#adjustments')).reset();
3+
Edit();
4+
});

src/index.ts

Lines changed: 0 additions & 36 deletions
This file was deleted.

src/loadFile.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
const loadFile = (event: any) => {
2+
//load the image
3+
const image: any = <HTMLImageElement>document.querySelector('#output')!;
4+
//display the image
5+
image.src = URL.createObjectURL(event.target.files[0]);
6+
(<HTMLButtonElement> document.querySelector('#export-image-btn'))!.disabled = false;
7+
Edit();
8+
};

0 commit comments

Comments
 (0)