Skip to content

Instantly share code, notes, and snippets.

@kaleocheng
Last active August 29, 2015 14:22
Show Gist options
  • Save kaleocheng/5b6b1840faf6efbc54f8 to your computer and use it in GitHub Desktop.
Save kaleocheng/5b6b1840faf6efbc54f8 to your computer and use it in GitHub Desktop.
删除某个文件夹里的讨厌的空白图像(圣光)
# -*- coding: utf-8 -*-
# !/usr/bin/python
# Filename: change_tint2_color.py
# 删除某个文件夹里的讨厌的空白图像(圣光)
from PIL import Image
import fnmatch
import os
def get_files_name(path):
"""获取文件夹内的文件的文件名"""
files_name = os.listdir(path)
for file_name in files_name:
if not fnmatch.fnmatch(file_name, '*.png'):
files_name.remove(file_name)
return files_name
def is_blank_image(image_name):
"""是否是空白图片"""
image = Image.open(image_name)
pix = image.load()
if pix[1200, 20] == (255, 255, 255, 0):
return True
else:
return False
def delete_files(files_name):
"""Delete files"""
for filename in files_name:
if os.path.isfile(filename):
os.remove(filename)
blank_images_name = []
os.chdir('./test/')
images_name = get_files_name('../test/')
for image_name in images_name:
if is_blank_image(image_name):
blank_images_name.append(image_name)
delete_files(blank_images_name)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment