Skip to content

Commit b87203e

Browse files
image_compressor
1 parent d745b8b commit b87203e

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

image_compress.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# For inforation on Pillow visit https://pypi.org/project/Pillow/
2+
import os, sys
3+
from PIL import Image
4+
5+
def compressMe(file, verbose = False):
6+
filepath = os.path.join(os.getcwd(), file)
7+
picture = Image.open(filepath)
8+
picture.save("Compressed_"+file, "JPEG", optimize = True, quality = 10)
9+
return
10+
11+
def main():
12+
verbose = False
13+
if (len(sys.argv)>1):
14+
if (sys.argv[1].lower()=="-v"):
15+
verbose = True
16+
cwd = os.getcwd()
17+
formats = ('.jpg', '.jpeg')
18+
19+
for file in os.listdir(cwd):
20+
if os.path.splitext(file)[1].lower() in formats:
21+
print('compressing', file)
22+
compressMe(file, verbose)
23+
print("Done")
24+
25+
# Driver code
26+
if __name__ == "__main__":
27+
main()

0 commit comments

Comments
 (0)