Il modulo imghdr determina il tipo di immagine contenuto in un file o in un flusso di dati.
Il modulo imghdr definisce le seguenti funzioni:
| filename[, h]) |
I seguenti tipi di immagini vengono riconosciuti, come i valori elencati qui sotto con il valore restituito da what():
| Valore | Formato dell'immagine |
|---|---|
'rgb' |
FIle SGI ImgLib |
'gif' |
FIle GIF 87a e 89a |
'pbm' |
File Bitmap Portabile |
'pgm' |
File Graymap Portabile |
'ppm' |
File Pixmap Portabile |
'tiff' |
File TIFF |
'rast' |
File Raster Sun |
'xbm' |
File X Bitmap |
'jpeg' |
Dati JPEG nel formato JFIF |
'bmp' |
File BMP |
'png' |
Portable Network Graphics |
Si può estendere la lista dei file che il tipo imghdr può riconoscere per aggiungerli a questa variabile:
None.
La funzione test dovrebbe restituire una stringa che descrive il tipo
di immagine se il test ha successo, o None se fallisce.
Esempio:
>>> import imghdr
>>> imghdr.what('/tmp/bass.gif')
'gif'