Movatterモバイル変換


[0]ホーム

URL:


Previous PageUp One LevelNext PagePython Library ReferenceContentsModule IndexIndex
Previous:14.8 rgbimgUp:14. Multimedia ServicesNext:14.10 sndhdr

14.9imghdr -- Determine the type of an image

Theimghdr module determines the type of image contained in afile or byte stream.

Theimghdr module defines the following function:

what(filename[, h])
Tests the image data contained in the file named byfilename,and returns a string describing the image type. If optionalhis provided, thefilename is ignored andh is assumed tocontain the byte stream to test.

The following image types are recognized, as listed below with thereturn value fromwhat():

Value Image format 
'rgb'SGI ImgLib Files
'gif'GIF 87a and 89a Files
'pbm'Portable Bitmap Files
'pgm'Portable Graymap Files
'ppm'Portable Pixmap Files
'tiff'TIFF Files
'rast'Sun Raster Files
'xbm'X Bitmap Files
'jpeg'JPEG data in JFIF format
'bmp'BMP files
'png'Portable Network Graphics

You can extend the list of file typesimghdr can recognize byappending to this variable:

tests
A list of functions performing the individual tests. Each functiontakes two arguments: the byte-stream and an open file-like object.Whenwhat() is called with a byte-stream, the file-likeobject will beNone.

The test function should return a string describing the image type ifthe test succeeded, orNone if it failed.

Example:

>>> import imghdr>>> imghdr.what('/tmp/bass.gif')'gif'


Previous PageUp One LevelNext PagePython Library ReferenceContentsModule IndexIndex
Previous:14.8 rgbimgUp:14. Multimedia ServicesNext:14.10 sndhdr
Release 2.2.3, documentation updated on 30 May 2003.
SeeAbout this document... for information on suggesting changes.
[8]ページ先頭

©2009-2026 Movatter.jp