aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorclarkzjw <[email protected]>2022-11-17 11:40:24 -0800
committerclarkzjw <[email protected]>2022-11-17 11:40:24 -0800
commit79590a402751361077bcfafa14db113cb719be82 (patch)
treefd5af389f41c593cba7bf9fc15b746e5db1d6317
parent36b13e7d3de9af582a88a1a5b2a3c29be3d40d54 (diff)
downloadSquare-79590a402751361077bcfafa14db113cb719be82.tar.gz
+ add batch processing
-rwxr-xr-xsquare.py45
1 files changed, 29 insertions, 16 deletions
diff --git a/square.py b/square.py
index 903e939..6cf3b48 100755
--- a/square.py
+++ b/square.py
@@ -1,9 +1,10 @@
1import sys 1import glob
2import argparse
2 3
3from PIL import Image, ImageFilter 4from PIL import Image, ImageFilter
4 5
5 6
6def insta_size_no_padding(img): 7def square_size_no_padding(img):
7 w, h = img.size 8 w, h = img.size
8 new = Image.new(img.mode, (max(w, h), max(w, h)), (255, 255, 255)) 9 new = Image.new(img.mode, (max(w, h), max(w, h)), (255, 255, 255))
9 if h >= w: 10 if h >= w:
@@ -13,7 +14,7 @@ def insta_size_no_padding(img):
13 return new 14 return new
14 15
15 16
16def insta_size_padding(img): 17def square_size_padding(img):
17 w, h = img.size 18 w, h = img.size
18 padding_percentage = 0.02 19 padding_percentage = 0.02
19 length = max(w, h) 20 length = max(w, h)
@@ -64,16 +65,28 @@ def drop_shadow(image, offset=(5, 5), background=0xffffff, shadow=0x444444, bord
64 65
65 66
66if __name__ == "__main__": 67if __name__ == "__main__":
67 if len(sys.argv) <= 1: 68 parser = argparse.ArgumentParser(description="Options")
68 exit(0) 69 parser.add_argument('--padding', action=argparse.BooleanOptionalAction)
69 for file in sys.argv[1:]: 70
70 names = file.split(".") 71 args = parser.parse_args()
71 if len(names) != 2: 72
72 continue 73 files = glob.glob("*")
73 try: 74 for file in files:
74 im = Image.open(file) 75 if (file.endswith(".jpg") or file.endswith(".png")) \
75 except Exception as e: 76 and (str.find(file, "result") == -1):
76 print(str(e)) 77
77 continue 78 names = file.split(".")
78 result = insta_size_no_padding(drop_shadow(im, background=0xFAFAFA, shadow=0x444444, offset=(20, 20))) 79 if len(names) != 2:
79 result.save("{}-square-shadow.{}".format(names[0], names[1]), quality=100) 80 continue
81 try:
82 im = Image.open(file)
83 except Exception as e:
84 print(str(e))
85 continue
86
87 print("Processing {}".format(file))
88 if args.padding is True:
89 result = square_size_padding(drop_shadow(im, background=0xFAFAFA, shadow=0x444444, offset=(20, 20)))
90 else:
91 result = square_size_no_padding(drop_shadow(im, background=0xFAFAFA, shadow=0x444444, offset=(20, 20)))
92 result.save("{}-result.{}".format(names[0], names[1]), quality=100)
Powered by cgit v1.2.3 (git 2.41.0)