diff --git a/Applications/ImageCompressor/README.md b/Applications/ImageCompressor/README.md new file mode 100644 index 0000000..9c34a54 --- /dev/null +++ b/Applications/ImageCompressor/README.md @@ -0,0 +1,24 @@ +# Image Compressor + +## 🛠️ Description + +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 + +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 + +:Simply run the script + + +## 🤖 Author + +If you have any doubts or tips feel free to ping me on discord + diff --git a/Applications/ImageCompressor/image_compressor.py b/Applications/ImageCompressor/image_compressor.py new file mode 100644 index 0000000..3e61bd7 --- /dev/null +++ b/Applications/ImageCompressor/image_compressor.py @@ -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() \ No newline at end of file diff --git a/Applications/ImageCompressor/requirements.txt b/Applications/ImageCompressor/requirements.txt new file mode 100644 index 0000000..cd4c0fc --- /dev/null +++ b/Applications/ImageCompressor/requirements.txt @@ -0,0 +1,3 @@ +os +pillow +easygui \ No newline at end of file