Skip to content

Commit

Permalink
Altering the script to run on Linux systems.
Browse files Browse the repository at this point in the history
Adding 'if statement' to change image mode to 'RGB' to solve IOError,
when saving to JPEG.

Adding 'sys.argv' to access global variables for image file and,
destination directory. Allows script to be reusable.

Adding comments to the script.
  • Loading branch information
ndarin committed Jul 8, 2021
1 parent 27d8e11 commit 2f54068
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions image_processing.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,23 @@
#!/usr/bin/env python3

from PIL import Image
import os, glob
import os, glob, sys

size = 128, 128

for infile in glob.glob("*.tiff"):
file, ext = os.path.splitext(infile)
path = sys.argv[1]
# first obtain a list of .tiff images from the images directory
for infile in glob.glob(path + '/*.tiff'):
# remove 'image/' and '.tiff' from infile variable and save file name
lane, _ = os.path.splitext(infile)
_, file = os.path.split(lane)
# open the image file
with Image.open(infile) as im:
# change image mode to 'RGB', necessary to convert to JPEG
if im.mode != 'RGB':
im = im.convert('RGB')
# convert image to thumbnail
im.thumbnail(size)
out = im.rotate(90)
out.save(file + ".jpg", "JPEG")
# rotate image and save output
out = im.rotate(-90)
# add the destination directory path '/opt/icon/' and save image
out.save(sys.argv[2] + file + "JPEG")

0 comments on commit 2f54068

Please sign in to comment.