User:Mirjam Dissel/image converter

From XPUB & Lens-Based wiki
< User:Mirjam Dissel
Revision as of 13:55, 23 April 2012 by Mirjam Dissel (talk | contribs) (Created page with "imageconverter.py <source lang="python"> import sys, os imagefolder = "img/" targetfolder = "resized/" if not os.path.isdir(targetfolder): os.mkdir(targetfolder) os.chdir(ima...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

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)