Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
6001CEM-Individual-Project/convertPngToTiff.py
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
50 lines (35 sloc)
1.69 KB
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
import os | |
import shutil | |
from PIL import Image | |
### Convert from [FORMAT_1] to [FORMAT_2] ### | |
### Uncomment when needed ### | |
##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() == ".tiff": | |
## if os.path.isfile(os.path.splitext(os.path.join(root, name))[0] + ".png"): | |
## print("A tiff file already exists for %s" % name) | |
## # If a png is *NOT* present, create one from the tiff. | |
## else: | |
## outfile = os.path.splitext(os.path.join(root, name))[0] + ".png" | |
## try: | |
## im = Image.open(os.path.join(root, name)) | |
## print("Generating png for %s" % name) | |
## im.thumbnail(im.size) | |
## im.save(outfile, "PNG", quality=100) | |
## except(Exception, e): | |
## print(e) | |
## os.remove(os.path.join(root,name)) | |
## | |
## Code adapted from Anbarasan Thangapalam | |
## https://stackoverflow.com/questions/28870504/converting-tiff-to-jpeg-in-python | |
###################################################### | |
### Split images to pre and post folders | |
yourpath = os.getcwd() | |
for root, dirs, files in os.walk(yourpath, topdown=False): | |
for name in files: | |
if 'post' in os.path.splitext(os.path.join(root, name))[0].lower(): | |
shutil.move(os.path.join(root, name),root+'\post\\') | |
elif 'pre' in os.path.splitext(os.path.join(root, name))[0].lower(): | |
shutil.move(os.path.join(root, name),root+'\pre\\') | |