⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 module-imghdr.html

📁 一本很好的python的说明书,适合对python感兴趣的人
💻 HTML
字号:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>14.9 imghdr -- Determine the type of an image</title>
<META NAME="description" CONTENT="14.9 imghdr -- Determine the type of an image">
<META NAME="keywords" CONTENT="lib">
<META NAME="resource-type" CONTENT="document">
<META NAME="distribution" CONTENT="global">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link rel="STYLESHEET" href="lib.css" tppabs="http://www.python.org/doc/current/lib/lib.css">
<LINK REL="next" href="module-sndhdr.html" tppabs="http://www.python.org/doc/current/lib/module-sndhdr.html">
<LINK REL="previous" href="module-rgbimg.html" tppabs="http://www.python.org/doc/current/lib/module-rgbimg.html">
<LINK REL="up" href="mmedia.html" tppabs="http://www.python.org/doc/current/lib/mmedia.html">
<LINK REL="next" href="module-sndhdr.html" tppabs="http://www.python.org/doc/current/lib/module-sndhdr.html">
</head>
<body>
<DIV CLASS="navigation"><table align="center" width="100%" cellpadding="0" cellspacing="2">
<tr>
<td><A href="module-rgbimg.html" tppabs="http://www.python.org/doc/current/lib/module-rgbimg.html"><img src="previous.gif" tppabs="http://www.python.org/doc/current/icons/previous.gif" border="0" height="32"
  alt="Previous Page" width="32"></A></td>
<td><A href="mmedia.html" tppabs="http://www.python.org/doc/current/lib/mmedia.html"><img src="up.gif" tppabs="http://www.python.org/doc/current/icons/up.gif" border="0" height="32"
  alt="Up One Level" width="32"></A></td>
<td><A href="module-sndhdr.html" tppabs="http://www.python.org/doc/current/lib/module-sndhdr.html"><img src="next.gif" tppabs="http://www.python.org/doc/current/icons/next.gif" border="0" height="32"
  alt="Next Page" width="32"></A></td>
<td align="center" width="100%">Python Library Reference</td>
<td><A href="contents.html" tppabs="http://www.python.org/doc/current/lib/contents.html"><img src="contents.gif" tppabs="http://www.python.org/doc/current/icons/contents.gif" border="0" height="32"
  alt="Contents" width="32"></A></td>
<td><a href="modindex.html" tppabs="http://www.python.org/doc/current/lib/modindex.html" title="Module Index"><img src="modules.gif" tppabs="http://www.python.org/doc/current/icons/modules.gif" border="0" height="32"
  alt="Module Index" width="32"></a></td>
<td><A href="genindex.html" tppabs="http://www.python.org/doc/current/lib/genindex.html"><img src="index.gif" tppabs="http://www.python.org/doc/current/icons/index.gif" border="0" height="32"
  alt="Index" width="32"></A></td>
</tr></table>
<b class="navlabel">Previous:</b> <a class="sectref" href="module-rgbimg.html" tppabs="http://www.python.org/doc/current/lib/module-rgbimg.html">14.8 rgbimg  </A>
<b class="navlabel">Up:</b> <a class="sectref" href="mmedia.html" tppabs="http://www.python.org/doc/current/lib/mmedia.html">14. Multimedia Services</A>
<b class="navlabel">Next:</b> <a class="sectref" href="module-sndhdr.html" tppabs="http://www.python.org/doc/current/lib/module-sndhdr.html">14.10 sndhdr  </A>
<br><hr></DIV>
<!--End of Navigation Panel-->

<H1><A NAME="SECTION0016900000000000000000">
14.9 <tt class="module">imghdr</tt> --
         Determine the type of an image</A>
</H1>

<P>


<P>
The <tt class="module">imghdr</tt> module determines the type of image contained in a
file or byte stream.

<P>
The <tt class="module">imghdr</tt> module defines the following function:

<P>
<dl><dt><b><a name='l2h-2933'><tt class='function'>what</tt></a></b> (<var>filename</var><big>[</big><var>, h</var><big>]</big>)
<dd>
Tests the image data contained in the file named by <var>filename</var>,
and returns a string describing the image type.  If optional <var>h</var>
is provided, the <var>filename</var> is ignored and <var>h</var> is assumed to
contain the byte stream to test.
</dl>

<P>
The following image types are recognized, as listed below with the
return value from <tt class="function">what()</tt>:

<P>
<table border align="center" style="border-collapse: collapse">
  <thead>
    <tr class="tableheader">
      <th align="left"><b>Value</b>&nbsp;</th>
      <th align="left"><b>Image format</b>&nbsp;</th>
    </thead>
  <tbody valign='baseline'>
    <tr><td align="left" valign="baseline"><code>'rgb'</code></td>
        <td align="left">SGI ImgLib Files</td>
    <tr><td align="left" valign="baseline"><code>'gif'</code></td>
        <td align="left">GIF 87a and 89a Files</td>
    <tr><td align="left" valign="baseline"><code>'pbm'</code></td>
        <td align="left">Portable Bitmap Files</td>
    <tr><td align="left" valign="baseline"><code>'pgm'</code></td>
        <td align="left">Portable Graymap Files</td>
    <tr><td align="left" valign="baseline"><code>'ppm'</code></td>
        <td align="left">Portable Pixmap Files</td>
    <tr><td align="left" valign="baseline"><code>'tiff'</code></td>
        <td align="left">TIFF Files</td>
    <tr><td align="left" valign="baseline"><code>'rast'</code></td>
        <td align="left">Sun Raster Files</td>
    <tr><td align="left" valign="baseline"><code>'xbm'</code></td>
        <td align="left">X Bitmap Files</td>
    <tr><td align="left" valign="baseline"><code>'jpeg'</code></td>
        <td align="left">JPEG data in JFIF format</td>
    <tr><td align="left" valign="baseline"><code>'bmp'</code></td>
        <td align="left">BMP files</td>
    <tr><td align="left" valign="baseline"><code>'png'</code></td>
        <td align="left">Portable Network Graphics</td></tbody>
</table>

<P>
You can extend the list of file types <tt class="module">imghdr</tt> can recognize by
appending to this variable:

<P>
<dl><dt><b><a name='l2h-2934'><tt>tests</tt></a></b>
<dd>
A list of functions performing the individual tests.  Each function
takes two arguments: the byte-stream and an open file-like object.
When <tt class="function">what()</tt> is called with a byte-stream, the file-like
object will be <code>None</code>.

<P>
The test function should return a string describing the image type if
the test succeeded, or <code>None</code> if it failed.
</dl>

<P>
Example:

<P>
<dl><dd><pre class="verbatim">
&gt;&gt;&gt; import imghdr
&gt;&gt;&gt; imghdr.what('/tmp/bass.gif')
'gif'
</pre></dl>

<DIV CLASS="navigation"><p><hr><table align="center" width="100%" cellpadding="0" cellspacing="2">
<tr>
<td><A href="module-rgbimg.html" tppabs="http://www.python.org/doc/current/lib/module-rgbimg.html"><img src="previous.gif" tppabs="http://www.python.org/doc/current/icons/previous.gif" border="0" height="32"
  alt="Previous Page" width="32"></A></td>
<td><A href="mmedia.html" tppabs="http://www.python.org/doc/current/lib/mmedia.html"><img src="up.gif" tppabs="http://www.python.org/doc/current/icons/up.gif" border="0" height="32"
  alt="Up One Level" width="32"></A></td>
<td><A href="module-sndhdr.html" tppabs="http://www.python.org/doc/current/lib/module-sndhdr.html"><img src="next.gif" tppabs="http://www.python.org/doc/current/icons/next.gif" border="0" height="32"
  alt="Next Page" width="32"></A></td>
<td align="center" width="100%">Python Library Reference</td>
<td><A href="contents.html" tppabs="http://www.python.org/doc/current/lib/contents.html"><img src="contents.gif" tppabs="http://www.python.org/doc/current/icons/contents.gif" border="0" height="32"
  alt="Contents" width="32"></A></td>
<td><a href="modindex.html" tppabs="http://www.python.org/doc/current/lib/modindex.html" title="Module Index"><img src="modules.gif" tppabs="http://www.python.org/doc/current/icons/modules.gif" border="0" height="32"
  alt="Module Index" width="32"></a></td>
<td><A href="genindex.html" tppabs="http://www.python.org/doc/current/lib/genindex.html"><img src="index.gif" tppabs="http://www.python.org/doc/current/icons/index.gif" border="0" height="32"
  alt="Index" width="32"></A></td>
</tr></table>
<b class="navlabel">Previous:</b> <a class="sectref" href="module-rgbimg.html" tppabs="http://www.python.org/doc/current/lib/module-rgbimg.html">14.8 rgbimg  </A>
<b class="navlabel">Up:</b> <a class="sectref" href="mmedia.html" tppabs="http://www.python.org/doc/current/lib/mmedia.html">14. Multimedia Services</A>
<b class="navlabel">Next:</b> <a class="sectref" href="module-sndhdr.html" tppabs="http://www.python.org/doc/current/lib/module-sndhdr.html">14.10 sndhdr  </A>
</DIV>
<!--End of Navigation Panel-->
<ADDRESS>
<hr>See <i><a href="about.html" tppabs="http://www.python.org/doc/current/lib/about.html">About this document...</a></i> for information on suggesting changes.
</ADDRESS>
</BODY>
</HTML>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -