Eremis
May 18th, 2010, 04:06 AM
Hi All!
I am making a program that will resize all pictures (JPEG) in a given directory. For my final product I want to be able to just do something like this:
Eremis@linux-machine:~$ python /home/Eremis/Pictures/Myphotos
and the result would resize every picture in that directory to a certain size (800 X 600 default). I don't want to worry about arguments yet (For size....). I just want to have a working program that would resize every single .JPG file into 800X600 size...
I have the code written to resize a single image, which I will post below. My question is how would I get all the files in a certain directory only with JPG ending and resize them with my resize function....
import Image
import os
def ResizePicture(pathFrom, pathTo = os.getenv('HOME'),width = 800, height = 600):
fileName = os.path.basename(pathFrom)
img = Image.open(pathFrom)
imgResized = img.resize((width, height), Image.ANTIALIAS)
picture.save(pathTo + '/' + fileName)
Thx!
I am making a program that will resize all pictures (JPEG) in a given directory. For my final product I want to be able to just do something like this:
Eremis@linux-machine:~$ python /home/Eremis/Pictures/Myphotos
and the result would resize every picture in that directory to a certain size (800 X 600 default). I don't want to worry about arguments yet (For size....). I just want to have a working program that would resize every single .JPG file into 800X600 size...
I have the code written to resize a single image, which I will post below. My question is how would I get all the files in a certain directory only with JPG ending and resize them with my resize function....
import Image
import os
def ResizePicture(pathFrom, pathTo = os.getenv('HOME'),width = 800, height = 600):
fileName = os.path.basename(pathFrom)
img = Image.open(pathFrom)
imgResized = img.resize((width, height), Image.ANTIALIAS)
picture.save(pathTo + '/' + fileName)
Thx!