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

An image compressor mini app has been added in application #72

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
24 changes: 24 additions & 0 deletions Applications/ImageCompressor/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Image Compressor

## 🛠️ Description
<!--Remove the below lines and add yours -->
The image resizer takes in an image and reduces it's disk size according to the quality you choose, the compressed image is saved in the folder of the orignal image



## ⚙️ Languages or Frameworks Used
<!--Remove the below lines and add yours -->
Modules required to be able to use the script successfully
`pillow`, `os`, `easygui`

These modules are listed in `requirements.txt` and can be installed by running the following command `pip install requirements.txt`

## 🌟 How to run
<!--Remove the below lines and add yours -->
:Simply run the script


## 🤖 Author
<!--Remove the below lines and add yours -->
If you have any doubts or tips feel free to ping me on discord

36 changes: 36 additions & 0 deletions Applications/ImageCompressor/image_compressor.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
from PIL import Image
import os
import easygui
from easygui import *

def resizer():
print("Please select the image you want to compress")
image_file = easygui.fileopenbox()
filepath = os.path.join(os.getcwd(), image_file)

filename, filextension = os.path.splitext(image_file)
img = Image.open(filepath)
text = "Enter quality on a scale of 10 to 100 (default value is 50)"

if filextension == ".jpeg" or filextension == ".jpg":
qual = integerbox(text,50,lowerbound=10,upperbound=100)
img.save(
filename + "_compressed" + ".jpeg",
"JPEG",
optimize= True,
quality = qual
)
msgbox("Your compressed image has been saved in the orignal image folder")

elif filextension == ".png":
img.convert("P", palette=Image.ADAPTIVE,colors=256)
img.save(filename+"_compressed"+".png",optimize=True,quality = 10)
msgbox("Please note that due to the file format being png it may not get compressed much")
msgbox("Your compressed image has been saved in the orignal image folder")

else:
print("Invalid filetype")

return

resizer()
3 changes: 3 additions & 0 deletions Applications/ImageCompressor/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
os
pillow
easygui