Skip to content

Adding Image-Inverter project #167

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

Merged
merged 21 commits into from
Jul 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
542d0ca
Added README.md file and inverter.py in Image-Inverter directory
0xcyb3rw0lf Jul 18, 2022
05d834a
Fixed README.md
0xcyb3rw0lf Jul 18, 2022
c502caf
Fixed link anchor in README.md, and corrected a word
0xcyb3rw0lf Jul 18, 2022
8dba3fa
Corrected a link anchor in README.md
0xcyb3rw0lf Jul 18, 2022
d114064
Corrected a function name typo in inverter.py
0xcyb3rw0lf Jul 18, 2022
e5318aa
fixed a typo in inverter.py
0xcyb3rw0lf Jul 24, 2022
1c594c3
Deleted ImageInverter directory
0xcyb3rw0lf Jul 24, 2022
f05aada
Added the code to avoid operating on the script call in sys.argv[0]
0xcyb3rw0lf Jul 24, 2022
20641b8
Added error handling to the conversion code
0xcyb3rw0lf Jul 24, 2022
6d50f03
Corrected a variable name
0xcyb3rw0lf Jul 24, 2022
62b1949
Removed try/except statment, and corrected the conversion part of the…
0xcyb3rw0lf Jul 24, 2022
daab44a
Removed unnecessary parameter in .save() function
0xcyb3rw0lf Jul 24, 2022
2ebec62
Moved input checking code to check_input() function.
0xcyb3rw0lf Jul 24, 2022
d9709ad
Edited a comment and changed a varialbe name for more clarity."
0xcyb3rw0lf Jul 24, 2022
ea6f5d1
Corrected project title.
0xcyb3rw0lf Jul 24, 2022
c75e9e8
Added Examples section, containig a demo command, before, and after i…
0xcyb3rw0lf Jul 24, 2022
0ccbdf9
Adding before and after images for README.md
0xcyb3rw0lf Jul 24, 2022
3f6db5b
Update README.md
0xcyb3rw0lf Jul 24, 2022
57a0674
Adding verbose feature
0xcyb3rw0lf Jul 25, 2022
f709c7d
Adding verbose section in README.md
0xcyb3rw0lf Jul 25, 2022
79eafda
Handled unsupported file types, such as .pdf
0xcyb3rw0lf Jul 25, 2022
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
21 changes: 21 additions & 0 deletions IMAGES & PHOTO SCRIPTS/Image-Inverter/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Image-Inverter

## Describtion
This project is an implementaion of a CLI program that inverts image/set of images.

## Requirements
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.

## Examples
### Command
`./inverter.py /your/path/to/image.jpg /another/img.png`

OR: you can use `-v` or `--verbose`:
`./inverter,py -v /your/image.webp`

NOTE: **output** images will be generated in the **current working directory**
### Before
![Flower's Normal Image](https://github.com/omar-danasoury/Python-project-Scripts/blob/25c0a96bc74e762bf74b9b33c56372e9d4f23837/IMAGES%20&%20PHOTO%20SCRIPTS/Image-Inverter/before.png)

### After
![Flower's Inverted Image](https://github.com/omar-danasoury/Python-project-Scripts/blob/25c0a96bc74e762bf74b9b33c56372e9d4f23837/IMAGES%20&%20PHOTO%20SCRIPTS/Image-Inverter/after.png)
Binary file added IMAGES & PHOTO SCRIPTS/Image-Inverter/after.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 IMAGES & PHOTO SCRIPTS/Image-Inverter/before.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
40 changes: 40 additions & 0 deletions IMAGES & PHOTO SCRIPTS/Image-Inverter/inverter.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#!/usr/bin/env python3

from PIL import Image, ImageOps, UnidentifiedImageError
import sys, os

def check_input():
""" Checks if the script is called with no input parameters. """
if len(sys.argv) == 1:
print("Please provide image files to operate on!")
sys.exit(1)

def main():
""" The main function """
check_input()

verbose_enabled = False
if ("-v" in sys.argv) or ("--verbose" in sys.argv):
verbose_enabled = True

i = 0
for file in sys.argv:
# To ignore the first parameter -> the script call + -v + --verbose
if i == 0 or sys.argv[i] == "-v" or sys.argv[i] == "--verbose":
i = i + 1
continue

image_path_no_ext, extension = os.path.splitext(file)

try:
with Image.open(file) as image:
new_path_with_ext = image_path_no_ext + "_inverted" + extension
ImageOps.invert(image).save(new_path_with_ext)
if verbose_enabled:
print("Successfully inverted " + file + "\n" + new_path_with_ext + " is generated.\n")
except UnidentifiedImageError:
print(file + " is not suppotred, please provide a supported file type.")
i = i + 1

if __name__ == '__main__':
main()