-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy paths.py
61 lines (47 loc) · 1.2 KB
/
s.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# add -v for verbose
# get Pillow (fork of PIL) from
# pip before running -->pip
# pip install Pillow
# import required libraries
import os
import sys
from tkinter import filedialog
from PIL import Image
from tkinter.filedialog import*
# define a function for
# compressing an image
def compressMe(file, verbose = False):
# Get the path of the file
# filepath = os.path.join(os.getcwd(),file)
filepath = askopenfilename()
# open the image
picture = Image.open(filepath)
print('compressing', filepath[37:])
picture.save("Compressed_"+filepath[37:],
"JPEG",
optimize = True,
quality = 10)
return
# Define a main function
def main():
verbose = False
# checks for verbose flag
if (len(sys.argv)>1):
if (sys.argv[1].lower()=="-v"):
verbose = True
# finds current working dir
# change working directory
cwd = os.chdir("Newfolder")
formats = ('.jpg', '.jpeg')
# looping through all the files
# in a current directory
for file in os.listdir(cwd):
# If the file format is JPG or JPEG
if os.path.splitext(file)[1].lower() in formats:
# print('compressing', file)
compressMe(file, verbose)
break
print("Done")
# Driver code
if __name__ == "__main__":
main()