Skip to content

Instantly share code, notes, and snippets.

@Paethon
Created June 6, 2013 19:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save Paethon/5724012 to your computer and use it in GitHub Desktop.
Save Paethon/5724012 to your computer and use it in GitHub Desktop.
Delete an image if it is completely black. To delete all black jpeg in a Folder call ./rmBlackImages.py *.jpg
import sys
import os
import Image
black = (0, 0, 0)
def imageIsColor(image, color):
width, height = image.size
pix = image.load()
for y in xrange(height):
for x in xrange(width):
if pix[x, y] != color:
return False
return True
# Process all files given by command line arguments
firstArgument = True # Used to ignore first argument which contains name of script
for arg in sys.argv:
if firstArgument:
firstArgument = False
continue
print 'Checking', arg
im = Image.open(arg)
if imageIsColor(im, black):
os.remove(arg)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment