Discussion:
available formats and params for Image.save()
News123
2009-07-23 09:56:45 UTC
Permalink
Hi,

Somehow I have difficulties reading the documentation for PIL (Image)

Is there an easy way to know which formats are supported and what their
names are?

Is there an easy way to know which parameters are supported by
Image.save(). How can I list them where are they documented?


Somehow I consider the documentation to be a little weak on this points.
class Image
. . .
save(self, fp, format=None, **params)
| Save image to file or stream
In order to find out how the format name for a .jpg file I did following:

import Image
img = Image.open("afile.jpg")
print img.format


Then I saw, that the result was 'JPEG' and not 'JPG' as I tried first

I'm at a complete loss at finding out what parameters the save function
accepts for saving a JPG file or a PNG file

Is there an easy way of finding this in any doc or do I have to dive
into the sources.


If there's no easy way:
Wouldn't a better documentation increase the 'user experience'?



Thanks in advance for any pointers


N
Gabriel Genellina
2009-07-24 09:47:37 UTC
Permalink
Post by News123
Somehow I have difficulties reading the documentation for PIL (Image)
Is there an easy way to know which formats are supported and what their
names are?
py> import PIL
py> from PIL import Image
py> Image.ID
[]
py> Image.init()
py> Image.ID
['PNG', 'ARG', 'BMP', 'BUFR', 'CUR', 'PCX', 'DCX', 'EPS', 'FITS', 'FLI',
'FPX',
'GBR', 'GIF', 'GRIB', 'HDF5', 'ICNS', 'ICO', 'IM', 'IMT', 'IPTC', 'JPEG',
'MCIDA
S', 'TIFF', 'MIC', 'MPEG', 'MSP', 'PCD', 'PIXAR', 'PPM', 'PSD', 'SGI',
'SPIDER',
'SUN', 'TGA', 'WBMP', 'WMF', 'XBM', 'XPM', 'XVTHUMB']
py> Image.OPEN.keys()
['PCX', 'ICNS', 'HDF5', 'SUN', 'MIC', 'EPS', 'MSP', 'FLI', 'FITS', 'GBR',
'WBMP'
, 'PCD', 'PIXAR', 'BUFR', 'PPM', 'WMF', 'SGI', 'BMP', 'TGA', 'DCX', 'ICO',
'CUR'
, 'XPM', 'TIFF', 'JPEG', 'SPIDER', 'GIF', 'GRIB', 'IM', 'IMT', 'IPTC',
'FPX', 'X
BM', 'MPEG', 'PSD', 'ARG', 'XVTHUMB', 'PNG', 'MCIDAS']
py> Image.SAVE.keys()
['XBM', 'PCX', 'SPIDER', 'HDF5', 'TIFF', 'BUFR', 'EPS', 'JPEG', 'MSP',
'GRIB', '
GIF', 'BMP', 'IM', 'PPM', 'PDF', 'FITS', 'PALM', 'WBMP', 'WMF', 'PNG']
Post by News123
Is there an easy way to know which parameters are supported by
Image.save(). How can I list them where are they documented?
That depends on the format being used. The PIL handbook lists the standard
formats used and their parameters:
http://www.pythonware.com/library/pil/handbook/index.htm
Post by News123
I'm at a complete loss at finding out what parameters the save function
accepts for saving a JPG file or a PNG file
http://www.pythonware.com/library/pil/handbook/format-jpeg.htm
--
Gabriel Genellina
News123
2009-07-25 20:29:29 UTC
Permalink
Thanks a lot Gabriel,

Your answer is perfect.

I was only looking in part II of the PIL manual and overlooked the
Appendix :-(.

I also apreciate
Image.ID , Image.SAVE , Image.OPEN

I saw them when typing
dir Image
but I never had the idea of calling Image.init() first

bye

N
Post by Gabriel Genellina
Post by News123
Somehow I have difficulties reading the documentation for PIL (Image)
Is there an easy way to know which formats are supported and what their
names are?
py> import PIL
py> from PIL import Image
py> Image.ID
[]
py> Image.init()
py> Image.ID
['PNG', 'ARG', 'BMP', 'BUFR', 'CUR', 'PCX', 'DCX', 'EPS', 'FITS', 'FLI',
'FPX',
'GBR', 'GIF', 'GRIB', 'HDF5', 'ICNS', 'ICO', 'IM', 'IMT', 'IPTC',
'JPEG', 'MCIDA
S', 'TIFF', 'MIC', 'MPEG', 'MSP', 'PCD', 'PIXAR', 'PPM', 'PSD', 'SGI',
'SPIDER',
'SUN', 'TGA', 'WBMP', 'WMF', 'XBM', 'XPM', 'XVTHUMB']
py> Image.OPEN.keys()
['PCX', 'ICNS', 'HDF5', 'SUN', 'MIC', 'EPS', 'MSP', 'FLI', 'FITS',
'GBR', 'WBMP'
, 'PCD', 'PIXAR', 'BUFR', 'PPM', 'WMF', 'SGI', 'BMP', 'TGA', 'DCX',
'ICO', 'CUR'
, 'XPM', 'TIFF', 'JPEG', 'SPIDER', 'GIF', 'GRIB', 'IM', 'IMT', 'IPTC',
'FPX', 'X
BM', 'MPEG', 'PSD', 'ARG', 'XVTHUMB', 'PNG', 'MCIDAS']
py> Image.SAVE.keys()
['XBM', 'PCX', 'SPIDER', 'HDF5', 'TIFF', 'BUFR', 'EPS', 'JPEG', 'MSP',
'GRIB', '
GIF', 'BMP', 'IM', 'PPM', 'PDF', 'FITS', 'PALM', 'WBMP', 'WMF', 'PNG']
Post by News123
Is there an easy way to know which parameters are supported by
Image.save(). How can I list them where are they documented?
That depends on the format being used. The PIL handbook lists the
http://www.pythonware.com/library/pil/handbook/index.htm
Post by News123
I'm at a complete loss at finding out what parameters the save function
accepts for saving a JPG file or a PNG file
http://www.pythonware.com/library/pil/handbook/format-jpeg.htm
Loading...