Skip to content

Instantly share code, notes, and snippets.

@mertkahyaoglu
Created February 24, 2017 13:21
Show Gist options
  • Save mertkahyaoglu/200a23d86d6a2f2b04fdb706eaf5373f to your computer and use it in GitHub Desktop.
Save mertkahyaoglu/200a23d86d6a2f2b04fdb706eaf5373f to your computer and use it in GitHub Desktop.
import os
from PIL import Image
yourpath = os.getcwd()
for root, dirs, files in os.walk(yourpath, topdown=False):
for name in files:
print(os.path.join(root, name))
if os.path.splitext(os.path.join(root, name))[1].lower() == ".tif":
outpath = os.path.splitext(os.path.join("dist", name))[0] + ".png"
if os.path.isfile(outpath):
print "exists: %s" % name
else:
try:
im = Image.open(os.path.join(root, name))
im_trimmed = im.crop(im.getbbox())
im_trimmed.thumbnail((350, 350))
im_trimmed.save(outpath, "PNG")
except Exception, e:
print e
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment