[Image-SIG] How to convert an Image in RGB to JPG
Frédéric Mantegazza
frederic.mantegazza at gbiloba.org
Wed Feb 27 07:28:18 CET 2008
On mardi 26 février 2008, Shabda Raaj wrote:
> This is the code I am trying and errors I get,
>
> >>> image = Image.new(mode='RGB', size = (10, 10))
> >>> image.convert('JPG')
>
> Traceback (most recent call last):
> File "<interactive input>", line 1, in ?
> File "C:\Python24\Lib\site-packages\PIL\Image.py", line 612, in
> convert im = im.convert(mode, dither)
> ValueError: conversion from RGB to JPG not supported
>
> >>> image.convert('jpg')
>
> Traceback (most recent call last):
> File "<interactive input>", line 1, in ?
> File "C:\Python24\Lib\site-packages\PIL\Image.py", line 612, in
> convert im = im.convert(mode, dither)
> ValueError: conversion from RGB to jpg not supported
>
>
> Basically I want to create an image, do some drawing on it and get the
> image as byte array. I am obviously missing some basic step, but I
> can't figure out what :(
'JPG" is not a valid mode ('RGB', 'RGBA', 'CMYK'... are). To get the image
as something near array, use image.getdata() method.
To save it as jpeg, just use image.save("myfile.jpg").
--
Frédéric
http://www.gbiloba.org
More information about the Image-SIG
mailing list