MCPcopy Create free account
hub / github.com/ndleah/python-mini-project / resizer

Function resizer

Image_compressor/image_compressor.py:6–34  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

4from easygui import *
5
6def resizer():
7 print("Please select the image you want to compress")
8 image_file = easygui.fileopenbox()
9 filepath = os.path.join(os.getcwd(), image_file)
10
11 filename, filextension = os.path.splitext(image_file)
12 img = Image.open(filepath)
13 text = "Enter quality on a scale of 10 to 100 (default value is 50)"
14
15 if filextension == ".jpeg" or filextension == ".jpg":
16 qual = integerbox(text,50,lowerbound=10,upperbound=100)
17 img.save(
18 filename + "_compressed" + ".jpeg",
19 "JPEG",
20 optimize= True,
21 quality = qual
22 )
23 msgbox("Your compressed image has been saved in the orignal image folder")
24
25 elif filextension == ".png":
26 img.convert("P", palette=Image.ADAPTIVE,colors=256)
27 img.save(filename+"_compressed"+".png",optimize=True,quality = 10)
28 msgbox("Please note that due to the file format being png it may not get compressed much")
29 msgbox("Your compressed image has been saved in the orignal image folder")
30
31 else:
32 print("Invalid filetype")
33
34 return
35
36resizer()

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected