Skip to content

Instantly share code, notes, and snippets.

@nakagami
Created May 21, 2013 01:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nakagami/5616920 to your computer and use it in GitHub Desktop.
Save nakagami/5616920 to your computer and use it in GitHub Desktop.
Walk and detect CMYK Jpeg, and print it's path name
#!/usr/bin/env python
"""
Detect CMYK Jpeg under current directory
use PIL (or Pillow)
"""
import os
from PIL import Image
START_PATH='.'
for (path, dirs, files) in os.walk(START_PATH):
for f in files:
_, ext = os.path.splitext(f)
if ext == '.jpg' or ext == '.jpeg':
p = os.path.join(path, f)
try:
image = Image.open(p)
if image.mode == 'CMYK':
print('CMYK', p)
except IOError as e:
print(e, p)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment