Skip to content

Commit c3610af

Browse files
authored
Merge pull request larymak#167 from omar-danasoury/main
Adding Image-Inverter project
2 parents 7a36ada + 79eafda commit c3610af

File tree

4 files changed

+61
-0
lines changed

4 files changed

+61
-0
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Image-Inverter
2+
3+
## Describtion
4+
This project is an implementaion of a CLI program that inverts image/set of images.
5+
6+
## Requirements
7+
First, you need to install `pillow` module. You can check the official instructions [here](https://pillow.readthedocs.io/en/stable/installation.html) and follow the instructions according to the OS you are running.
8+
9+
## Examples
10+
### Command
11+
`./inverter.py /your/path/to/image.jpg /another/img.png`
12+
13+
OR: you can use `-v` or `--verbose`:
14+
`./inverter,py -v /your/image.webp`
15+
16+
NOTE: **output** images will be generated in the **current working directory**
17+
### Before
18+
![Flower's Normal Image](https://github.com/omar-danasoury/Python-project-Scripts/blob/25c0a96bc74e762bf74b9b33c56372e9d4f23837/IMAGES%20&%20PHOTO%20SCRIPTS/Image-Inverter/before.png)
19+
20+
### After
21+
![Flower's Inverted Image](https://github.com/omar-danasoury/Python-project-Scripts/blob/25c0a96bc74e762bf74b9b33c56372e9d4f23837/IMAGES%20&%20PHOTO%20SCRIPTS/Image-Inverter/after.png)
Loading
Loading
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#!/usr/bin/env python3
2+
3+
from PIL import Image, ImageOps, UnidentifiedImageError
4+
import sys, os
5+
6+
def check_input():
7+
""" Checks if the script is called with no input parameters. """
8+
if len(sys.argv) == 1:
9+
print("Please provide image files to operate on!")
10+
sys.exit(1)
11+
12+
def main():
13+
""" The main function """
14+
check_input()
15+
16+
verbose_enabled = False
17+
if ("-v" in sys.argv) or ("--verbose" in sys.argv):
18+
verbose_enabled = True
19+
20+
i = 0
21+
for file in sys.argv:
22+
# To ignore the first parameter -> the script call + -v + --verbose
23+
if i == 0 or sys.argv[i] == "-v" or sys.argv[i] == "--verbose":
24+
i = i + 1
25+
continue
26+
27+
image_path_no_ext, extension = os.path.splitext(file)
28+
29+
try:
30+
with Image.open(file) as image:
31+
new_path_with_ext = image_path_no_ext + "_inverted" + extension
32+
ImageOps.invert(image).save(new_path_with_ext)
33+
if verbose_enabled:
34+
print("Successfully inverted " + file + "\n" + new_path_with_ext + " is generated.\n")
35+
except UnidentifiedImageError:
36+
print(file + " is not suppotred, please provide a supported file type.")
37+
i = i + 1
38+
39+
if __name__ == '__main__':
40+
main()

0 commit comments

Comments
 (0)