papiez_ipsum/src/pope_sanitizer

44 lines
1.1 KiB
Python

#!/usr/bin/env python
import PIL.Image
from glob import glob
from os import path
import os
exts = [".jpg", ".jpeg", ".png", ".gif"]
def remove(pope):
if os.path.isdir(pope):
return
pope_dir = path.dirname(pope)
borked_path = path.join(pope_dir, "borked")
if not path.exists(borked_path):
os.mkdir(borked_path)
file = os.path.split(pope)[1]
move_to = os.path.join(borked_path, file)
os.rename(pope, move_to)
for pope in ["JP2", "B16"]:
print("dealing with {}".format(pope))
pope_images = glob("popes/{pope}/*".format(pope=pope))
for image in (x for x in pope_images if not path.isdir(x)):
try:
i = PIL.Image.open(image)
x, y = i.size
except:
print("{image} seems to be borked".format(image=image))
input()
if x < 300 or y < 300:
print("{image} seems to be small".format(image=image))
remove(image)
ext = path.splitext(image)[1]
if ext not in exts :
print("{image} seems to have a fucked up extension".format(image=image))