<!DOCTYPE html PUBLIC
"-//W3C//DTD HTML 4.0 Transitional//EN">
<link rel=
"STYLESHEET" href=
"lib.css" type='text/css'
/>
<link rel=
"SHORTCUT ICON" href=
"../icons/pyfav.png" type=
"image/png" />
<link rel='start' href='../index.html' title='Python Documentation Index'
/>
<link rel=
"first" href=
"lib.html" title='Python Library Reference'
/>
<link rel='contents' href='contents.html'
title=
"Contents" />
<link rel='index' href='genindex.html' title='Index'
/>
<link rel='last' href='about.html' title='About this document...'
/>
<link rel='help' href='about.html' title='About this document...'
/>
<link rel=
"prev" href=
"module-imgfile.html" />
<link rel=
"parent" href=
"sgi.html" />
<link rel=
"next" href=
"sunos.html" />
<meta name='aesop' content='information'
/>
<title>20.12 jpeg -- Read and write JPEG files
</title>
<div id='top-navigation-panel' xml:id='top-navigation-panel'
>
<table align=
"center" width=
"100%" cellpadding=
"0" cellspacing=
"2">
<td class='online-navigation'
><a rel=
"prev" title=
"20.11 imgfile "
href=
"module-imgfile.html"><img src='../icons/previous.png'
border='
0' height='
32' alt='Previous Page' width='
32'
/></A></td>
<td class='online-navigation'
><a rel=
"parent" title=
"20. SGI IRIX Specific"
href=
"sgi.html"><img src='../icons/up.png'
border='
0' height='
32' alt='Up One Level' width='
32'
/></A></td>
<td class='online-navigation'
><a rel=
"next" title=
"21. SunOS Specific Services"
href=
"sunos.html"><img src='../icons/next.png'
border='
0' height='
32' alt='Next Page' width='
32'
/></A></td>
<td align=
"center" width=
"100%">Python Library Reference
</td>
<td class='online-navigation'
><a rel=
"contents" title=
"Table of Contents"
href=
"contents.html"><img src='../icons/contents.png'
border='
0' height='
32' alt='Contents' width='
32'
/></A></td>
<td class='online-navigation'
><a href=
"modindex.html" title=
"Module Index"><img src='../icons/modules.png'
border='
0' height='
32' alt='Module Index' width='
32'
/></a></td>
<td class='online-navigation'
><a rel=
"index" title=
"Index"
href=
"genindex.html"><img src='../icons/index.png'
border='
0' height='
32' alt='Index' width='
32'
/></A></td>
<div class='online-navigation'
>
<b class=
"navlabel">Previous:
</b>
<a class=
"sectref" rel=
"prev" href=
"module-imgfile.html">20.11 imgfile
</A>
<b class=
"navlabel">Up:
</b>
<a class=
"sectref" rel=
"parent" href=
"sgi.html">20. SGI IRIX Specific
</A>
<b class=
"navlabel">Next:
</b>
<a class=
"sectref" rel=
"next" href=
"sunos.html">21. SunOS Specific Services
</A>
<!--End of Navigation Panel-->
<H1><A NAME=
"SECTION00221200000000000000000">
20.12 <tt class=
"module">jpeg
</tt> --
Read and write JPEG files
</A>
<A NAME=
"module-jpeg"></A>
<p class=
"availability">Availability:
<span
class=
"platform">IRIX
</span>.
</p>
The module
<tt class=
"module">jpeg
</tt> provides access to the jpeg compressor and
decompressor written by the Independent JPEG Group
<a id='l2h-
5218' xml:id='l2h-
5218'
></a>(IJG). JPEG is a standard for
compressing pictures; it is defined in ISO
10918. For details on JPEG
or the Independent JPEG Group software refer to the JPEG standard or
the documentation provided with the software.
A portable interface to JPEG image files is available with the Python
Imaging Library (PIL) by Fredrik Lundh. Information on PIL is
available at
<a class=
"url" href=
"http://www.pythonware.com/products/pil/">http://www.pythonware.com/products/pil/
</a>.
<a id='l2h-
5219' xml:id='l2h-
5219'
></a>
The
<tt class=
"module">jpeg
</tt> module defines an exception and some functions.
<dl><dt><b><span class=
"typelabel">exception
</span> <tt id='l2h-
5214' xml:id='l2h-
5214'
class=
"exception">error
</tt></b></dt>
Exception raised by
<tt class=
"function">compress()
</tt> and
<tt class=
"function">decompress()
</tt>
<dl><dt><table cellpadding=
"0" cellspacing=
"0"><tr valign=
"baseline">
<td><nobr><b><tt id='l2h-
5215' xml:id='l2h-
5215'
class=
"function">compress
</tt></b>(
</nobr></td>
<td><var>data, w, h, b
</var>)
</td></tr></table></dt>
Treat data as a pixmap of width
<var>w
</var> and height
<var>h
</var>, with
<var>b
</var> bytes per pixel. The data is in SGI GL order, so the first
pixel is in the lower-left corner. This means that
<tt class=
"function">gl.lrectread()
</tt>
return data can immediately be passed to
<tt class=
"function">compress()
</tt>.
Currently only
1 byte and
4 byte pixels are allowed, the former being
treated as greyscale and the latter as RGB color.
<tt class=
"function">compress()
</tt> returns a string that contains the compressed
picture, in JFIF
<a id='l2h-
5220' xml:id='l2h-
5220'
></a> format.
<dl><dt><table cellpadding=
"0" cellspacing=
"0"><tr valign=
"baseline">
<td><nobr><b><tt id='l2h-
5216' xml:id='l2h-
5216'
class=
"function">decompress
</tt></b>(
</nobr></td>
<td><var>data
</var>)
</td></tr></table></dt>
Data is a string containing a picture in JFIF
<a id='l2h-
5221' xml:id='l2h-
5221'
></a> format. It
returns a tuple
<code>(
<var>data
</var>,
<var>width
</var>,
<var>height
</var>,
<var>bytesperpixel
</var>)
</code>. Again, the data is suitable to pass to
<tt class=
"function">gl.lrectwrite()
</tt>.
<dl><dt><table cellpadding=
"0" cellspacing=
"0"><tr valign=
"baseline">
<td><nobr><b><tt id='l2h-
5217' xml:id='l2h-
5217'
class=
"function">setoption
</tt></b>(
</nobr></td>
<td><var>name, value
</var>)
</td></tr></table></dt>
Set various options. Subsequent
<tt class=
"function">compress()
</tt> and
<tt class=
"function">decompress()
</tt> calls will use these options. The following
<div class=
"center"><table class=
"realtable">
<th class=
"left" >Option
</th>
<th class=
"left" >Effect
</th>
<tr><td class=
"left" valign=
"baseline"><code>'forcegray'
</code></td>
<td class=
"left" >Force output to be grayscale, even if input is RGB.
</td></tr>
<tr><td class=
"left" valign=
"baseline"><code>'quality'
</code></td>
<td class=
"left" >Set the quality of the compressed image to a value between
<code>0</code> and
<code>100</code> (default is
<code>75</code>). This only affects
<tr><td class=
"left" valign=
"baseline"><code>'optimize'
</code></td>
<td class=
"left" >Perform Huffman table optimization. Takes longer, but results in
smaller compressed image. This only affects compression.
</td></tr>
<tr><td class=
"left" valign=
"baseline"><code>'smooth'
</code></td>
<td class=
"left" >Perform inter-block smoothing on uncompressed image. Only useful
for low-quality images. This only affects decompression.
</td></tr></tbody>
<p class=
"heading">See Also:
</p>
<dl compact=
"compact" class=
"seetitle">
<dt><em class=
"citetitle"
>JPEG Still Image Data Compression Standard
</em></dt>
canonical reference for the JPEG image format, by
Pennebaker and Mitchell.
</dd>
<dl compact=
"compact" class=
"seetitle">
<dt><em class=
"citetitle"><a href=
"http://www.w3.org/Graphics/JPEG/itu-t81.pdf"
Technology - Digital Compression and Coding of
Continuous-tone Still Images - Requirements and
<dd>The ISO standard for JPEG is also published as
ITU T
.81. This is available online in PDF form.
</dd>
<div class='online-navigation'
>
<table align=
"center" width=
"100%" cellpadding=
"0" cellspacing=
"2">
<td class='online-navigation'
><a rel=
"prev" title=
"20.11 imgfile "
href=
"module-imgfile.html"><img src='../icons/previous.png'
border='
0' height='
32' alt='Previous Page' width='
32'
/></A></td>
<td class='online-navigation'
><a rel=
"parent" title=
"20. SGI IRIX Specific"
href=
"sgi.html"><img src='../icons/up.png'
border='
0' height='
32' alt='Up One Level' width='
32'
/></A></td>
<td class='online-navigation'
><a rel=
"next" title=
"21. SunOS Specific Services"
href=
"sunos.html"><img src='../icons/next.png'
border='
0' height='
32' alt='Next Page' width='
32'
/></A></td>
<td align=
"center" width=
"100%">Python Library Reference
</td>
<td class='online-navigation'
><a rel=
"contents" title=
"Table of Contents"
href=
"contents.html"><img src='../icons/contents.png'
border='
0' height='
32' alt='Contents' width='
32'
/></A></td>
<td class='online-navigation'
><a href=
"modindex.html" title=
"Module Index"><img src='../icons/modules.png'
border='
0' height='
32' alt='Module Index' width='
32'
/></a></td>
<td class='online-navigation'
><a rel=
"index" title=
"Index"
href=
"genindex.html"><img src='../icons/index.png'
border='
0' height='
32' alt='Index' width='
32'
/></A></td>
<div class='online-navigation'
>
<b class=
"navlabel">Previous:
</b>
<a class=
"sectref" rel=
"prev" href=
"module-imgfile.html">20.11 imgfile
</A>
<b class=
"navlabel">Up:
</b>
<a class=
"sectref" rel=
"parent" href=
"sgi.html">20. SGI IRIX Specific
</A>
<b class=
"navlabel">Next:
</b>
<a class=
"sectref" rel=
"next" href=
"sunos.html">21. SunOS Specific Services
</A>
<span class=
"release-info">Release
2.4.2, documentation updated on
28 September
2005.
</span>
<!--End of Navigation Panel-->
See
<i><a href=
"about.html">About this document...
</a></i> for information on suggesting changes.