mirror of
https://github.com/metafy-social/python-scripts.git
synced 2024-11-23 20:11:10 +00:00
Merge pull request #63 from muratonuryildirim/master
Issue No: 55. tiff to png/jpeg converter
This commit is contained in:
commit
8618617f1e
7
scripts/tiff_converter/readme.md
Normal file
7
scripts/tiff_converter/readme.md
Normal file
|
@ -0,0 +1,7 @@
|
|||
# TIFF to PNG/JPEG
|
||||
A simple script converts TIFF files to (i).png and (ii).jpeg
|
||||
|
||||
## Usage
|
||||
* Dependency:
|
||||
* Pillow
|
||||
* Use `python3 -m pip install --upgrade Pillow`
|
27
scripts/tiff_converter/script.py
Normal file
27
scripts/tiff_converter/script.py
Normal file
|
@ -0,0 +1,27 @@
|
|||
import os
|
||||
from PIL import Image
|
||||
|
||||
|
||||
def tiff_to_jpeg():
|
||||
path = os.getcwd()
|
||||
for root, dirs, files in os.walk(path):
|
||||
for name in files:
|
||||
if os.path.splitext(os.path.join(root, name))[1].lower() == ".tiff":
|
||||
outfile = os.path.splitext(os.path.join(root, name))[0] + ".jpg"
|
||||
im = Image.open(os.path.join(root, name)).convert('RGB')
|
||||
im.thumbnail(im.size)
|
||||
im.save(outfile, "JPEG", quality=90)
|
||||
print('.tiff file(s) are converted to .jpeg')
|
||||
|
||||
|
||||
def tiff_to_png():
|
||||
|
||||
path = os.getcwd()
|
||||
for root, dirs, files in os.walk(path):
|
||||
for name in files:
|
||||
if os.path.splitext(os.path.join(root, name))[1].lower() == ".tiff":
|
||||
outfile = os.path.splitext(os.path.join(root, name))[0] + ".png"
|
||||
im = Image.open(os.path.join(root, name)).convert('RGB')
|
||||
im.thumbnail(im.size)
|
||||
im.save(outfile, "PNG", quality=90)
|
||||
print('.tiff file(s) are converted to .png')
|
Loading…
Reference in New Issue
Block a user