Skip to content

Instantly share code, notes, and snippets.

@aliyevorkhan
Created September 21, 2020 19:17
Show Gist options
  • Save aliyevorkhan/fe0526e951d28ecbbdda385e59963cd7 to your computer and use it in GitHub Desktop.
Save aliyevorkhan/fe0526e951d28ecbbdda385e59963cd7 to your computer and use it in GitHub Desktop.
import os
from PIL import Image
def has_transparency(img):
if img.mode == "P":
transparent = img.info.get("transparency", -1)
for _, index in img.getcolors():
if index == transparent:
return True
elif img.mode == "RGBA":
extrema = img.getextrema()
if extrema[3][0] < 255:
return True
return False
for file in os.listdir(os.getcwd()+'/Neutral'):
img = Image.open(os.getcwd()+'/Neutral/'+file)
if (has_transparency(img)):
os.remove(os.getcwd()+'/Neutral/'+file)
print('deleted')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment