Created
February 24, 2017 13:21
-
-
Save mertkahyaoglu/200a23d86d6a2f2b04fdb706eaf5373f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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