Convert all images to JPEG

Fredrik Lundh fredrik at
Wed Dec 29 09:34:07 CET 2004

"Thomas" <2002 at> wrote:

> I got a bunch of different images of different types ( bmp, gif, png,
> tiff etc ) and I want to convert them all to JPEGs using PIL. Is this
> possible? When I try I get all sorts of errors, doing something like :
> im = # might be png, gif etc, for instance
> test1.png
> im.thumbnail(size, Image.ANTIALIAS) # size is 640x480
>, "JPEG") # targetname is test1.jpg
> produces an exception. Any clues?

the exception contains a pretty strong clue:

    "IOError: cannot write mode P as JPEG"


    if im.mode != "RGB":
        im = im.convert("RGB")

between the open and thumbnail calls fixes this.


More information about the Python-list mailing list