Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.
This example uses the ImageSet
library to convert an entire directory of images to the .jpg format. It first uses the ImageSet to load the directory of images. It
then iterates through the set, changing the name of the file to have a
.jpg extension. Then it saves the
file again with the new file extension and automatically converts it to
the new file format during the save process.
from SimpleCV import ImageSet
set = ImageSet(".")
for img in set:
oldname = img.filename
newname = oldname[0:-3] + 'jpg'
print "Converting " + oldname + " to " + newname
img.save(newname) 