Welcome to smc.freeimage’s documentation!

Contents:

Supported image formats

Image formats supported by FreeImage and PIL.

Plugin FIT mimetype description FreeImage read FreeImage write PIL read PIL write extensions
BMP 0 image/bmp Windows or OS/2 Bitmap 1 1 1 1 bmp
BUFR       0 0 1 1 bufr
CUT 21 image/x-cut Dr. Halo 1 0 0 0 cut
DCX     Intel FAX container format 0 0 1 0 dcx
DDS 24 image/x-dds DirectX Surface 1 0 0 0 dds
EPS   application/postscript Encapsulated Postscript 0 0 1 1 eps, ps
EXR 29 image/x-exr ILM OpenEXR 1 1 0 0 exr
FITS       0 0 1 1 fit, fits
FLI     Autodesk FLI/FLC Animation 0 0 1 0 flc, fli
FPX     FlashPix 0 0 1 0 fpx
G3 27 image/fax-g3 Raw fax format CCITT G.3 1 0 0 0 g3
GBR     GIMP brush file 0 0 1 0 gbr
GIF 25 image/gif Graphics Interchange Format 1 1 1 1 gif
GRIB       0 0 identify 0 grib
HDF5       0 0 identify 0 h5, hdf
HDR 26 image/vnd.radiance High Dynamic Range Image 1 1 0 0 hdr
ICNS     Mac OS icns resource 0 0 1 0 icns
ICO 1 image/vnd.microsoft.icon Windows Icon 1 1 1 0 ico
IFF 5 image/x-iff IFF Interleaved Bitmap 1 0 0 0 iff, lbm
IM     IFUNC Image Memory 0 0 1 1 im
IMT     IM Tools 0 0 1 0  
J2K 30 image/j2k JPEG-2000 codestream 1 1 0 0 j2k, j2c
JNG 3 image/x-mng JPEG Network Graphics 1 1 0 0 jng
JP2 31 image/jp2 JPEG-2000 File Format 1 1 0 0 jp2
JPEG 2 image/jpeg JPEG - JFIF Compliant 1 1 1 1 jpg, jif, jpeg, jpe
KOALA 4 image/x-koala C64 Koala Graphics 1 0 0 0 koa
MCIDAS     McIdas area file 0 0 1 0  
MIC     Microsoft Image Composer 0 0 1 0 mic
MNG 6 video/x-mng Multiple-image Network Graphics 1 0 0 0 mng
MPEG       0 0 identify 0 mpeg, mpg
MSP     Windows Paint 0 0 1 1 msp
PALM   image/palm   0 0 0 1 palm
PBM 7 image/freeimage-pnm Portable Bitmap (ASCII) 1 1 1 1 pbm
PBMRAW 8 image/freeimage-pnm Portable Bitmap (RAW) 1 1 1 1 pbm
PCD 9 image/x-photo-cd Kodak PhotoCD 1 0 0 0 pcd
PCX 10 image/x-pcx Zsoft Paintbrush 1 0 1 1 pcx
PDF   application/pdf   0 0 0 1 pdf
PFM 32 image/x-portable-floatmap Portable floatmap 1 1 0 0 pfm
PGM 11 image/freeimage-pnm Portable Greymap (ASCII) 1 1 1 1 pgm
PGMRAW 12 image/freeimage-pnm Portable Greymap (RAW) 1 1 0 0 pgm
PICT 33 image/x-pict Macintosh PICT 1 0 0 0 pct, pict, pic
PIXAR     PIXAR raster image 0 0 1 0  
PNG 13 image/png Portable Network Graphics 1 1 1 1 png
PPM 14 image/freeimage-pnm Portable Pixelmap (ASCII) 1 1 1 1 ppm
PPMRAW 15 image/freeimage-pnm Portable Pixelmap (RAW) 1 1 0 0 ppm
PSD 20 image/vnd.adobe.photoshop Adobe Photoshop 1 0 1 0 psd
RAS 16 image/x-cmu-raster Sun Raster Image 1 0 1 0 ras
RAW 34 image/x-dcraw RAW camera image 1 0 0 0 3fr, arw, bay, bmq, cap, cine, cr2, crw, cs1, dc2, dcr, drf, dsc, dng, erf, fff, ia, iiq, k25, kc2, kdc, mdc, mef, mos, mrw, nef, nrw, orf, pef, ptx, pxn, qtk, raf, raw, rdc, rw2, rwl, rwz, sr2, srf, srw, sti
SGI 28 image/x-sgi SGI Image Format 1 0 1 0 sgi
SPIDER       0 0 1 1  
TARGA 17 image/x-tga Truevision Targa 1 1 1 1 tga, targa
TIFF 18 image/tiff Tagged Image File Format 1 1 limited limited tif, tiff
      TIFF G3 compression 1 1 0 0  
      TIFF G4 compression 1 1 0 0  
      multipage TIFF 1 1 0 0  
WBMP 19 image/vnd.wap.wbmp Wireless Bitmap 1 1 0 0 wap, wbmp, wbm
WMF     Windows Metafile 0 0 identify 0 emf, wmf
XBM 22 image/x-xbitmap X11 Bitmap Format 1 0 1 1 xbm
XPM 23 image/x-xpixmap X11 Pixmap Format 1 1 1 0 xpm
XVTHUMB     XV thumbnail image 0 0 1 0  

PIL has only a limited support for TIFF files. Some compression schemas and multipage TIFFs aren’t supported by PIL 1.1.7.

Image

class smc.freeimage.Image

Image(filename[, buffer=None[, flags=0]])

Create a new Image. Either filename or buffer must applied.

adjustBrightness(brigthness=0.0) → None
adjustColors()

adjustColors(brightness=0.0, contrast=0.0, gamma=1.0, invert=False) -> None

adjustContrast(contrast=0.0) → None
adjustGamma(gamma=1.0) → None
bpp

bpp -> int

bits per pixel

clone() → new image

@note: clone uses low level FI functions to clone metadata and ICC, too.

close() → None

Close the image and free all resources. The close operation fails when a buffer is still using the image data.

closed

closed -> bool

color_type

color_type -> int (fi.FIC_*)

Get color type of the image, e.g. fi.FIC_MINISBLACK, fi.FIC_RGB, fi.FIC_CMYK ...

color_type_name

color_type_name -> str

colororder

Get color order (BGR or RGB)

The color order depends on the endianess of the system

colors_used

colors_used -> int

Returns number of colors used in the image (palette-size) or 0 for high color images.

convert_16bits555() → new image
convert_16bits565() → new image
convert_24bits() → new image
convert_32bits() → new image
convert_4bits() → new image
convert_8bits() → new image
convert_rgbf() → new image
crop(left: int, top: int, right: int, bottom: int) → new image
dither(dither_alg) → new image

Converts a bitmap to 1-bit monochrome bitmap using a dithering algorithm.

dpi

dpi -> (dpi_x: int, dpi_y: int)

dpi_x

dpi_x -> int

Dots per inch (x axis)

dpi_y

dpi_y -> int

Dots per inch (y axis)

dpm

dpm -> (dpm_x: int, dpm_y: int)

dpm_x

dpm_x -> int

Dots per meter (x axis)

dpm_y

dpm_y -> int

Dots per meter (y axis)

filename

filename

flipHorizontal() → new image
flipVertical() → new image
floodfill(red, green, blue) → None

Fill the entire image

format

format -> int (fi.FIF_*)

Format is the image format like fi.FIF_JPEG or fi.FIF_PNG.

getHistogram()

getHistogramm([channel=fi.FICC_BLACK]) -> list[256]

getICC() → str

Return ICC profile a byte string

getInfoHeader() → BitmapInfo instance
getMetadata() → dict

@param binary: if true, return values as binary instead of unicode string @param strict: encoding error handling for unicode string conversion

getMetadataCount() → dict

Count number of metadata for each model

getRaw()

Get raw data

Returns raw image data as bytes. It’s up to you to interpret the raw bytes according to image type, bpp, color order and stride padding.

@note: FreeImage stores the lines upside down @return: copy of raw image data @rtype: bytes

greyscale() → new image
has_bg_color

has_bg_color -> bool

has_icc

has_icc -> bool

Returns true if the image has an ICC profile

has_pixels

Check if image is loaded with fi.FIF_LOAD_NOPIXELS

@return: True if image has pixel and isn’t loaded with fi.FIF_LOAD_NOPIXELS

iccTransform()

Apply an LCMS transformation

icc_cmyk

icc_cmyk -> bool

invert() → None
is_transparent

is_transparent -> bool

mimetype

mimetype -> str

mimetype of the image, e.g. image/jpeg

paste(src: Image, left: int, top: int[, alpha=256]) → None

Paste source image into this image.

alpha: 0 to 255 for alpha blending or 256 for combination.

pitch

pitch -> int

Get pitch of scan lines (width + padding)

removeICC()

Remove ICC profile

resize(width: int, height: int[, filter=FILTER_BOX]) → new image
rgb_mask

Get bitmask for red, green and blue channel

rotate(angle: int) → new image

Only angles 90, 180 and 270 degrees are supported

Warning: rotation will result in loose of metadata

rotateEx()

rotate(angle: double, ...) -> new image

wrapper around fi.FreeImage_RotateEx

angle: angle in degree

save(filename[, format=-1[, flags=0]])

Save image to file

size

size -> (width: int, height: int)

threshold(threshold: int) → new image

Converts a bitmap to 1-bit monochrome bitmap

@param threshold: 0 to 255

toBuffer()

toBuffer([format=-1[, flags=0]] -> _MemoryIO instance

Access raw data of the image as read-only buffer or file like object

toPIL()

toPIL([format=-1[, flags=0]] -> PIL image

to_standard([scale_linear=True]) → new image
to_type(dst_type[, scale_linear=True]) → new image
type

type -> int (fi.FIT_*)

Type referes to the data type of the image like fi.FIT_BITMAP or fi.FIT_RGBF.

class smc.freeimage.Multipage

Multipage image support

filename

filename

format

format -> int (fi.FIF_*)

Format is the image format like fi.FIF_JPEG or fi.FIF_PNG.

size

size -> (width: int, height: int)

smc.freeimage.jpegTransform(source: str, destination: str, op: int) → None

Perform lossless rotation or flipping on a JPEG image

@param src: path to source image @type src: str @param dst: path to destination file, can be the same file as src @typ dst: str @param op: a FIJPEG_OP_* constant @param perfect: if true raises an exception if image has odd iMCU

aligned (see PDF)

Format and color helpers

class smc.freeimage.FormatInfo
classmethod from_file(path) → FormatInfo instance

Guess format from file

classmethod from_filename(filename) → FormatInfo instance

Guess format from filename

classmethod from_mimetype(mime) → FormatInfo instance

Guess format from mime type string

classmethod list()

Iterate over all supported formats

class smc.freeimage.ImageDataRepresentation
smc.freeimage.getColorOrder()

Get color order or RGB data

The color order is platform dependent.

big endian: RGB(A) little endian: BGR(A)

Windows and X86 platforms are usually little endian machines while PowerPC is usually big endian. ARM processors support both endianess.

@return: either “RGB” or “BGR” @rtype: str

smc.freeimage.getColorIndexRGBA()

Get index of RGBA quad

@return: R, G, B, A @rtype: tuple of four ints

smc.freeimage.getColorMaskRGBA()

Get color mask of RGBA quad

@return: R, G, B, A @rtype: tuple of four ints

smc.freeimage.getColorShiftRGBA()

Get color shift of RGBA quad

@return: R, G, B, A @rtype: tuple of four ints

smc.freeimage.getColorMask555()

Get color mask of 16bit 555 image

@return: R, G, B @rtype: tuple of three ints

smc.freeimage.getColorShift555()

Get color shift of 16bit 555 image

@return: R, G, B @rtype: tuple of three ints

smc.freeimage.getColorMask565()

Get color mask of 16bit 565 image

@return: R, G, B @rtype: tuple of three ints

smc.freeimage.getColorShift565()

Get color shift of 16bit 565 image

@return: R, G, B @rtype: tuple of three ints

smc.freeimage.lookupX11Color(name) -> (r, g, b)
smc.freeimage.lookupSVGColor(name) -> (r, g, b)

Color Management

class smc.freeimage.LCMSTransformation
class smc.freeimage.LCMSIccCache
class smc.freeimage.LCMSProfileInfo
smc.freeimage.getLCMSVersion()
smc.freeimage.XYZ2xyY()
smc.freeimage.xyY2XYZ()
smc.freeimage.getIntents()

Other helper functions

smc.freeimage.getVersion() → str

Get version of loaded freeimage library

smc.freeimage.getCompiledFor() -> tuple(major, minor, serial)
smc.freeimage.getCopyright() → str
smc.freeimage.hasJPEGTurbo()

Is FreeImage compiled against libjeg-turbo

Exception

exception smc.freeimage.FreeImageError
exception smc.freeimage.UnknownImageError
exception smc.freeimage.LoadError
exception smc.freeimage.SaveError
exception smc.freeimage.OperationError
exception smc.freeimage.LCMSException

Indices and tables