-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathp_image_flip.py
45 lines (36 loc) · 1.34 KB
/
p_image_flip.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
from PIL import Image
import os, pprint
os.chdir("C:\\Users\Cameron\\Desktop\\LibGDXGames\\Vigem\\rawassets")
#Storage for the filtered files
desired_files =[]
# @param-endswith checks if the word ends with the string
# @param-filter is the string we are searching for, will return empty list if not found
def filter_files(files, filter, endswith=""):
list = []
for file in files:
file_name = str(file)
if filter in file_name and file_name.endswith(endswith):
list.append(file_name)
return list
def swap_pixels(image, xy, uv):
temp_pixel = image.getpixel(xy)
image.putpixel(xy, image.getpixel(uv))
image.putpixel(uv, temp_pixel)
#0,0 is in the top left hand corner
def reverse_image(image):
for x in range(0, int(image.width/2)):
for y in range(0, int(image.height)):
swap_pixels(image, (x, y), (image.width-x-1, y))
for root, dirs, filepaths in os.walk(os.getcwd()):
desired_files = filepaths
desired_files = filter_files(desired_files, ".png")
#printing files for debug
pprint.pprint(desired_files)
desired_files = filter_files(desired_files, "right", endswith=".png")
#printing new files for debug
pprint.pprint(desired_files)
for file in desired_files:
image = Image.open(file)
reverse_image(image)
file = file.replace("right", "left")
image.save(file, "PNG")