Created
June 21, 2022 03:16
-
-
Save mikezucc/e29751c40ad89b2f82b82613044df102 to your computer and use it in GitHub Desktop.
Recursively convert .tiffs to .jpgs
This file contains 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
# python3 | |
import os | |
from PIL import Image | |
yourpath = os.getcwd() | |
for root, dirs, files in os.walk(yourpath, topdown=False): | |
for name in files: | |
if ".tif" in os.path.splitext(os.path.join(root, name))[1].lower(): | |
if os.path.isfile(os.path.splitext(os.path.join(root, name))[0] + ".jpg"): | |
print("A jpeg file already exists for %s" % name) | |
# If a jpeg is *NOT* present, create one from the tiff. | |
else: | |
outfile = os.path.splitext(os.path.join(root, name))[0] + ".jpg" | |
print(outfile) | |
try: | |
im = Image.open(os.path.join(root, name)) | |
print("Generating jpeg for %s" % name) | |
im.thumbnail(im.size) | |
im.save(outfile, "JPEG", quality=100) | |
except Exception as e: | |
print(e) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment