Ich habe mir ein Script zusammengebaut, und es funktioniert sogar so wie ich es will.
Trotzdem habe ich einige Fragen denn dieses Skript soll weiteren Übungen dienen.
1) Was haltet ihr von den Namen meiner Variablen und den Docstrings ?
2) Sollte ich lieber die zwei Zeilen:
Code: Alles auswählen
file_no_ext = os.path.splitext(inputpic)[0]
file_full_path = os.path.join(pic_search_path , inputpic
Cu Sebastian
Code: Alles auswählen
#!/usr/bin/python
#Version (0.01)
import sys, os, Image
pic_search_path="/home/sabba/in/pic/"
thumb_height=100
def create_thumb(inputpic, max_h):
""" creates a thumb of a pic by a given height with original aspectratio
Paramters:
inputpic = full path to pic
max_h = (in pixel) used to calculate new_w by aspectratio of inputpic
"""
file_no_ext = os.path.splitext(inputpic)[0]
file_full_path = os.path.join(pic_search_path , inputpic)
im = Image.open(file_full_path)
w, h = im.size
new_w = max_h * w / h
im.thumbnail((new_w, max_h), Image.ANTIALIAS)
im.save(pic_search_path + file_no_ext + "-thumb.jpg", "JPEG")
print "Thumb created:"
print "--> " + pic_search_path + file_no_ext + "-thumb.jpg"
print " "
def every_image_in_folder(inputfolder):
""" walks through a given folder and calls create_thumb() for every image
Paramters:
inputfolder = folder with original pics
"""
for i in os.listdir(inputfolder):
create_thumb(i, thumb_height)
def main():
every_image_in_folder(pic_search_path)
main()