-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBulkImageFlipMirror.py
55 lines (44 loc) · 1.52 KB
/
BulkImageFlipMirror.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
#!/usr/bin/env python3
'''
BulkImageFlipMirror.py v0.1.0
Python script for bulk flipping mirrored images in directory
Author: Kim Eirik Kvassheim
URL: https://github.com/kek91
License: MIT
'''
from os import path, makedirs
from glob import glob
from PIL import Image, ImageOps
print("\nBulkImageRotater.py\n\
Rotates all images in selected folder 90 degrees clockwise.\n\
https://github.com/kek91/scripts\n")
IMAGES_SRC = input((r"Source directory: "))
IMAGES_DST = IMAGES_SRC + "\\Flipped"
EXTENSIONS = ["jpg", "jpeg", "png", "bmp", "tiff", "gif"]
print("\nProcessing files in " + IMAGES_SRC + ", please wait...\n")
INDEX_IMG = 0
INDEX_OTHER = 0
if not path.exists(IMAGES_DST):
makedirs(IMAGES_DST)
for f in glob(IMAGES_SRC+"\\*.*", recursive=True):
filename = path.basename(f)
fileext = path.splitext(f)[1].lower().strip(".")
if fileext in EXTENSIONS:
try:
img = Image.open(f)
print("Flipping:\t", filename)
img = ImageOps.mirror(img)
img.save(IMAGES_DST+"\\"+filename)
#img.rotate(-90, expand=True).save(IMAGES_DST+"\\"+filename)
INDEX_IMG += 1
except IOError:
print("Skipping:\t", filename)
INDEX_OTHER += 1
else:
print("Skipping:\t", filename)
INDEX_OTHER += 1
print("\nBulk image flipper has finished. Results:\n\n\
Processed images:\t" + str(INDEX_IMG) + "\n\
Invalid files:\t\t" + str(INDEX_OTHER) + "\n\n\
Destination:\t\t" + IMAGES_DST + "\n\n")
keep_window_open = input()