User:Mirjam Dissel/image converter

From XPUB & Lens-Based wiki

imageconverter.py

import sys, os

imagefolder = "img/"
targetfolder = "resized/"

if not os.path.isdir(targetfolder):
	os.mkdir(targetfolder)

os.chdir(imagefolder)
imagelist = os.listdir(".")
for image in imagelist:
	currentImage = image.split(".")[0]
	extension = image.split(".")[1]
#	print "currentImage: {0} extension: {1}".format(currentImage,extension)
	newImage = "../resized/{0}_resized.{1}".format(currentImage,extension)
#	print newImage
	command = "convert {0} -quiet -resize 300x300^ -gravity center -extent 300x300 {1}".format(image,newImage)
	os.system(command)