PIL Package (autodoc of remaining modules)

Reference for modules whose documentation has not yet been ported or written can be found here.

BdfFontFile Module

class PIL.BdfFontFile.BdfFontFile(fp)[source]

Bases: PIL.FontFile.FontFile

PIL.BdfFontFile.bdf_char(f)[source]

ContainerIO Module

class PIL.ContainerIO.ContainerIO(file, offset, length)[source]
isatty()[source]
read(n=0)[source]
readline()[source]
readlines()[source]
seek(offset, mode=0)[source]
tell()[source]

ExifTags Module

FontFile Module

class PIL.FontFile.FontFile[source]
bitmap = None
compile()[source]

Create metrics and bitmap

save(filename)

Save font in version 1 format

save1(filename)[source]

Save font in version 1 format

save2(filename)[source]

Save font in version 2 format

PIL.FontFile.puti16(fp, values)[source]

GdImageFile Module

class PIL.GdImageFile.GdImageFile(fp=None, filename=None)[source]

Bases: PIL.ImageFile.ImageFile

format = 'GD'
format_description = 'GD uncompressed images'
PIL.GdImageFile.open(fp, mode='r')[source]

GimpGradientFile Module

class PIL.GimpGradientFile.GimpGradientFile(fp)[source]

Bases: PIL.GimpGradientFile.GradientFile

class PIL.GimpGradientFile.GradientFile[source]
getpalette(entries=256)[source]
gradient = None
PIL.GimpGradientFile.curved(middle, pos)[source]
PIL.GimpGradientFile.linear(middle, pos)[source]
PIL.GimpGradientFile.sine(middle, pos)[source]
PIL.GimpGradientFile.sphere_decreasing(middle, pos)[source]
PIL.GimpGradientFile.sphere_increasing(middle, pos)[source]

GimpPaletteFile Module

class PIL.GimpPaletteFile.GimpPaletteFile(fp)[source]
getpalette()[source]
rawmode = 'RGB'

ImageCms Module

class PIL.ImageCms.ImageCmsProfile(profile)[source]
class PIL.ImageCms.ImageCmsTransform(input, output, input_mode, output_mode, intent=0, proof=None, proof_intent=3, flags=0)[source]

Bases: PIL.Image.ImagePointHandler

Transform. This can be used with the procedural API, or with the standard Image.point() method.

apply(im, imOut=None)[source]
apply_in_place(im)[source]
point(im)[source]
exception PIL.ImageCms.PyCMSError[source]

Bases: exceptions.Exception

(pyCMS) Exception class. This is used for all errors in the pyCMS API.

PIL.ImageCms.applyTransform(im, transform, inPlace=0)[source]

(pyCMS) Applies a transform to a given image.

If im.mode != transform.inMode, a PyCMSError is raised.

If inPlace == TRUE and transform.inMode != transform.outMode, a PyCMSError is raised.

If im.mode, transfer.inMode, or transfer.outMode is not supported by pyCMSdll or the profiles you used for the transform, a PyCMSError is raised.

If an error occurs while the transform is being applied, a PyCMSError is raised.

This function applies a pre-calculated transform (from ImageCms.buildTransform() or ImageCms.buildTransformFromOpenProfiles()) to an image. The transform can be used for multiple images, saving considerable calcuation time if doing the same conversion multiple times.

If you want to modify im in-place instead of receiving a new image as the return value, set inPlace to TRUE. This can only be done if transform.inMode and transform.outMode are the same, because we can’t change the mode in-place (the buffer sizes for some modes are different). The default behavior is to return a new Image object of the same dimensions in mode transform.outMode.

参数:
  • im – A PIL Image object, and im.mode must be the same as the inMode supported by the transform.
  • transform – A valid CmsTransform class object
  • inPlace – Bool (1 == True, 0 or None == False). If True, im is modified in place and None is returned, if False, a new Image object with the transform applied is returned (and im is not changed). The default is False.
返回:

Either None, or a new PIL Image object, depending on the value of inPlace

引发 PyCMSError:

PIL.ImageCms.buildProofTransform(inputProfile, outputProfile, proofProfile, inMode, outMode, renderingIntent=0, proofRenderingIntent=3, flags=16384)[source]

(pyCMS) Builds an ICC transform mapping from the inputProfile to the outputProfile, but tries to simulate the result that would be obtained on the proofProfile device.

If the input, output, or proof profiles specified are not valid filenames, a PyCMSError will be raised.

If an error occurs during creation of the transform, a PyCMSError will be raised.

If inMode or outMode are not a mode supported by the outputProfile (or by pyCMS), a PyCMSError will be raised.

This function builds and returns an ICC transform from the inputProfile to the outputProfile, but tries to simulate the result that would be obtained on the proofProfile device using renderingIntent and proofRenderingIntent to determine what to do with out-of-gamut colors. This is known as “soft-proofing”. It will ONLY work for converting images that are in inMode to images that are in outMode color format (PIL mode, i.e. “RGB”, “RGBA”, “CMYK”, etc.).

Usage of the resulting transform object is exactly the same as with ImageCms.buildTransform().

Proof profiling is generally used when using an output device to get a good idea of what the final printed/displayed image would look like on the proofProfile device when it’s quicker and easier to use the output device for judging color. Generally, this means that the output device is a monitor, or a dye-sub printer (etc.), and the simulated device is something more expensive, complicated, or time consuming (making it difficult to make a real print for color judgement purposes).

Soft-proofing basically functions by adjusting the colors on the output device to match the colors of the device being simulated. However, when the simulated device has a much wider gamut than the output device, you may obtain marginal results.

参数:
  • inputProfile – String, as a valid filename path to the ICC input profile you wish to use for this transform, or a profile object
  • outputProfile – String, as a valid filename path to the ICC output (monitor, usually) profile you wish to use for this transform, or a profile object
  • proofProfile – String, as a valid filename path to the ICC proof profile you wish to use for this transform, or a profile object
  • inMode – String, as a valid PIL mode that the appropriate profile also supports (i.e. “RGB”, “RGBA”, “CMYK”, etc.)
  • outMode – String, as a valid PIL mode that the appropriate profile also supports (i.e. “RGB”, “RGBA”, “CMYK”, etc.)
  • renderingIntent

    Integer (0-3) specifying the rendering intent you wish to use for the input->proof (simulated) transform

    INTENT_PERCEPTUAL = 0 (DEFAULT) (ImageCms.INTENT_PERCEPTUAL) INTENT_RELATIVE_COLORIMETRIC = 1 (ImageCms.INTENT_RELATIVE_COLORIMETRIC) INTENT_SATURATION = 2 (ImageCms.INTENT_SATURATION) INTENT_ABSOLUTE_COLORIMETRIC = 3 (ImageCms.INTENT_ABSOLUTE_COLORIMETRIC)

    see the pyCMS documentation for details on rendering intents and what they do.

  • proofRenderingIntent

    Integer (0-3) specifying the rendering intent you wish to use for proof->output transform

    INTENT_PERCEPTUAL = 0 (DEFAULT) (ImageCms.INTENT_PERCEPTUAL) INTENT_RELATIVE_COLORIMETRIC = 1 (ImageCms.INTENT_RELATIVE_COLORIMETRIC) INTENT_SATURATION = 2 (ImageCms.INTENT_SATURATION) INTENT_ABSOLUTE_COLORIMETRIC = 3 (ImageCms.INTENT_ABSOLUTE_COLORIMETRIC)

    see the pyCMS documentation for details on rendering intents and what they do.

  • flags – Integer (0-...) specifying additional flags
返回:

A CmsTransform class object.

引发 PyCMSError:

PIL.ImageCms.buildProofTransformFromOpenProfiles(inputProfile, outputProfile, proofProfile, inMode, outMode, renderingIntent=0, proofRenderingIntent=3, flags=16384)

(pyCMS) Builds an ICC transform mapping from the inputProfile to the outputProfile, but tries to simulate the result that would be obtained on the proofProfile device.

If the input, output, or proof profiles specified are not valid filenames, a PyCMSError will be raised.

If an error occurs during creation of the transform, a PyCMSError will be raised.

If inMode or outMode are not a mode supported by the outputProfile (or by pyCMS), a PyCMSError will be raised.

This function builds and returns an ICC transform from the inputProfile to the outputProfile, but tries to simulate the result that would be obtained on the proofProfile device using renderingIntent and proofRenderingIntent to determine what to do with out-of-gamut colors. This is known as “soft-proofing”. It will ONLY work for converting images that are in inMode to images that are in outMode color format (PIL mode, i.e. “RGB”, “RGBA”, “CMYK”, etc.).

Usage of the resulting transform object is exactly the same as with ImageCms.buildTransform().

Proof profiling is generally used when using an output device to get a good idea of what the final printed/displayed image would look like on the proofProfile device when it’s quicker and easier to use the output device for judging color. Generally, this means that the output device is a monitor, or a dye-sub printer (etc.), and the simulated device is something more expensive, complicated, or time consuming (making it difficult to make a real print for color judgement purposes).

Soft-proofing basically functions by adjusting the colors on the output device to match the colors of the device being simulated. However, when the simulated device has a much wider gamut than the output device, you may obtain marginal results.

参数:
  • inputProfile – String, as a valid filename path to the ICC input profile you wish to use for this transform, or a profile object
  • outputProfile – String, as a valid filename path to the ICC output (monitor, usually) profile you wish to use for this transform, or a profile object
  • proofProfile – String, as a valid filename path to the ICC proof profile you wish to use for this transform, or a profile object
  • inMode – String, as a valid PIL mode that the appropriate profile also supports (i.e. “RGB”, “RGBA”, “CMYK”, etc.)
  • outMode – String, as a valid PIL mode that the appropriate profile also supports (i.e. “RGB”, “RGBA”, “CMYK”, etc.)
  • renderingIntent

    Integer (0-3) specifying the rendering intent you wish to use for the input->proof (simulated) transform

    INTENT_PERCEPTUAL = 0 (DEFAULT) (ImageCms.INTENT_PERCEPTUAL) INTENT_RELATIVE_COLORIMETRIC = 1 (ImageCms.INTENT_RELATIVE_COLORIMETRIC) INTENT_SATURATION = 2 (ImageCms.INTENT_SATURATION) INTENT_ABSOLUTE_COLORIMETRIC = 3 (ImageCms.INTENT_ABSOLUTE_COLORIMETRIC)

    see the pyCMS documentation for details on rendering intents and what they do.

  • proofRenderingIntent

    Integer (0-3) specifying the rendering intent you wish to use for proof->output transform

    INTENT_PERCEPTUAL = 0 (DEFAULT) (ImageCms.INTENT_PERCEPTUAL) INTENT_RELATIVE_COLORIMETRIC = 1 (ImageCms.INTENT_RELATIVE_COLORIMETRIC) INTENT_SATURATION = 2 (ImageCms.INTENT_SATURATION) INTENT_ABSOLUTE_COLORIMETRIC = 3 (ImageCms.INTENT_ABSOLUTE_COLORIMETRIC)

    see the pyCMS documentation for details on rendering intents and what they do.

  • flags – Integer (0-...) specifying additional flags
返回:

A CmsTransform class object.

引发 PyCMSError:

PIL.ImageCms.buildTransform(inputProfile, outputProfile, inMode, outMode, renderingIntent=0, flags=0)[source]

(pyCMS) Builds an ICC transform mapping from the inputProfile to the outputProfile. Use applyTransform to apply the transform to a given image.

If the input or output profiles specified are not valid filenames, a PyCMSError will be raised. If an error occurs during creation of the transform, a PyCMSError will be raised.

If inMode or outMode are not a mode supported by the outputProfile (or by pyCMS), a PyCMSError will be raised.

This function builds and returns an ICC transform from the inputProfile to the outputProfile using the renderingIntent to determine what to do with out-of-gamut colors. It will ONLY work for converting images that are in inMode to images that are in outMode color format (PIL mode, i.e. “RGB”, “RGBA”, “CMYK”, etc.).

Building the transform is a fair part of the overhead in ImageCms.profileToProfile(), so if you’re planning on converting multiple images using the same input/output settings, this can save you time. Once you have a transform object, it can be used with ImageCms.applyProfile() to convert images without the need to re-compute the lookup table for the transform.

The reason pyCMS returns a class object rather than a handle directly to the transform is that it needs to keep track of the PIL input/output modes that the transform is meant for. These attributes are stored in the “inMode” and “outMode” attributes of the object (which can be manually overridden if you really want to, but I don’t know of any time that would be of use, or would even work).

参数:
  • inputProfile – String, as a valid filename path to the ICC input profile you wish to use for this transform, or a profile object
  • outputProfile – String, as a valid filename path to the ICC output profile you wish to use for this transform, or a profile object
  • inMode – String, as a valid PIL mode that the appropriate profile also supports (i.e. “RGB”, “RGBA”, “CMYK”, etc.)
  • outMode – String, as a valid PIL mode that the appropriate profile also supports (i.e. “RGB”, “RGBA”, “CMYK”, etc.)
  • renderingIntent

    Integer (0-3) specifying the rendering intent you wish to use for the transform

    INTENT_PERCEPTUAL = 0 (DEFAULT) (ImageCms.INTENT_PERCEPTUAL) INTENT_RELATIVE_COLORIMETRIC = 1 (ImageCms.INTENT_RELATIVE_COLORIMETRIC) INTENT_SATURATION = 2 (ImageCms.INTENT_SATURATION) INTENT_ABSOLUTE_COLORIMETRIC = 3 (ImageCms.INTENT_ABSOLUTE_COLORIMETRIC)

    see the pyCMS documentation for details on rendering intents and what they do.

  • flags – Integer (0-...) specifying additional flags
返回:

A CmsTransform class object.

引发 PyCMSError:

PIL.ImageCms.buildTransformFromOpenProfiles(inputProfile, outputProfile, inMode, outMode, renderingIntent=0, flags=0)

(pyCMS) Builds an ICC transform mapping from the inputProfile to the outputProfile. Use applyTransform to apply the transform to a given image.

If the input or output profiles specified are not valid filenames, a PyCMSError will be raised. If an error occurs during creation of the transform, a PyCMSError will be raised.

If inMode or outMode are not a mode supported by the outputProfile (or by pyCMS), a PyCMSError will be raised.

This function builds and returns an ICC transform from the inputProfile to the outputProfile using the renderingIntent to determine what to do with out-of-gamut colors. It will ONLY work for converting images that are in inMode to images that are in outMode color format (PIL mode, i.e. “RGB”, “RGBA”, “CMYK”, etc.).

Building the transform is a fair part of the overhead in ImageCms.profileToProfile(), so if you’re planning on converting multiple images using the same input/output settings, this can save you time. Once you have a transform object, it can be used with ImageCms.applyProfile() to convert images without the need to re-compute the lookup table for the transform.

The reason pyCMS returns a class object rather than a handle directly to the transform is that it needs to keep track of the PIL input/output modes that the transform is meant for. These attributes are stored in the “inMode” and “outMode” attributes of the object (which can be manually overridden if you really want to, but I don’t know of any time that would be of use, or would even work).

参数:
  • inputProfile – String, as a valid filename path to the ICC input profile you wish to use for this transform, or a profile object
  • outputProfile – String, as a valid filename path to the ICC output profile you wish to use for this transform, or a profile object
  • inMode – String, as a valid PIL mode that the appropriate profile also supports (i.e. “RGB”, “RGBA”, “CMYK”, etc.)
  • outMode – String, as a valid PIL mode that the appropriate profile also supports (i.e. “RGB”, “RGBA”, “CMYK”, etc.)
  • renderingIntent

    Integer (0-3) specifying the rendering intent you wish to use for the transform

    INTENT_PERCEPTUAL = 0 (DEFAULT) (ImageCms.INTENT_PERCEPTUAL) INTENT_RELATIVE_COLORIMETRIC = 1 (ImageCms.INTENT_RELATIVE_COLORIMETRIC) INTENT_SATURATION = 2 (ImageCms.INTENT_SATURATION) INTENT_ABSOLUTE_COLORIMETRIC = 3 (ImageCms.INTENT_ABSOLUTE_COLORIMETRIC)

    see the pyCMS documentation for details on rendering intents and what they do.

  • flags – Integer (0-...) specifying additional flags
返回:

A CmsTransform class object.

引发 PyCMSError:

PIL.ImageCms.createProfile(colorSpace, colorTemp=-1)[source]

(pyCMS) Creates a profile.

If colorSpace not in [“LAB”, “XYZ”, “sRGB”], a PyCMSError is raised

If using LAB and colorTemp != a positive integer, a PyCMSError is raised.

If an error occurs while creating the profile, a PyCMSError is raised.

Use this function to create common profiles on-the-fly instead of having to supply a profile on disk and knowing the path to it. It returns a normal CmsProfile object that can be passed to ImageCms.buildTransformFromOpenProfiles() to create a transform to apply to images.

参数:
  • colorSpace – String, the color space of the profile you wish to create. Currently only “LAB”, “XYZ”, and “sRGB” are supported.
  • colorTemp – Positive integer for the white point for the profile, in degrees Kelvin (i.e. 5000, 6500, 9600, etc.). The default is for D50 illuminant if omitted (5000k). colorTemp is ONLY applied to LAB profiles, and is ignored for XYZ and sRGB.
返回:

A CmsProfile class object

引发 PyCMSError:

PIL.ImageCms.getDefaultIntent(profile)[source]

(pyCMS) Gets the default intent name for the given profile.

If profile isn’t a valid CmsProfile object or filename to a profile, a PyCMSError is raised.

If an error occurs while trying to obtain the default intent, a PyCMSError is raised.

Use this function to determine the default (and usually best optomized) rendering intent for this profile. Most profiles support multiple rendering intents, but are intended mostly for one type of conversion. If you wish to use a different intent than returned, use ImageCms.isIntentSupported() to verify it will work first.

参数:profile – EITHER a valid CmsProfile object, OR a string of the filename of an ICC profile.
返回:Integer 0-3 specifying the default rendering intent for this profile.
INTENT_PERCEPTUAL = 0 (DEFAULT) (ImageCms.INTENT_PERCEPTUAL) INTENT_RELATIVE_COLORIMETRIC = 1 (ImageCms.INTENT_RELATIVE_COLORIMETRIC) INTENT_SATURATION = 2 (ImageCms.INTENT_SATURATION) INTENT_ABSOLUTE_COLORIMETRIC = 3 (ImageCms.INTENT_ABSOLUTE_COLORIMETRIC)

see the pyCMS documentation for details on rendering intents and what they do.

引发 PyCMSError:
PIL.ImageCms.getOpenProfile(profileFilename)[source]

(pyCMS) Opens an ICC profile file.

The PyCMSProfile object can be passed back into pyCMS for use in creating transforms and such (as in ImageCms.buildTransformFromOpenProfiles()).

If profileFilename is not a vaild filename for an ICC profile, a PyCMSError will be raised.

参数:profileFilename – String, as a valid filename path to the ICC profile you wish to open, or a file-like object.
返回:A CmsProfile class object.
引发 PyCMSError:
PIL.ImageCms.getProfileCopyright(profile)[source]

(pyCMS) Gets the copyright for the given profile.

If profile isn’t a valid CmsProfile object or filename to a profile, a PyCMSError is raised.

If an error occurs while trying to obtain the copyright tag, a PyCMSError is raised

Use this function to obtain the information stored in the profile’s copyright tag.

参数:profile – EITHER a valid CmsProfile object, OR a string of the filename of an ICC profile.
返回:A string containing the internal profile information stored in an ICC tag.
引发 PyCMSError:
PIL.ImageCms.getProfileDescription(profile)[source]

(pyCMS) Gets the description for the given profile.

If profile isn’t a valid CmsProfile object or filename to a profile, a PyCMSError is raised.

If an error occurs while trying to obtain the description tag, a PyCMSError is raised

Use this function to obtain the information stored in the profile’s description tag.

参数:profile – EITHER a valid CmsProfile object, OR a string of the filename of an ICC profile.
返回:A string containing the internal profile information stored in an ICC tag.
引发 PyCMSError:
PIL.ImageCms.getProfileInfo(profile)[source]

(pyCMS) Gets the internal product information for the given profile.

If profile isn’t a valid CmsProfile object or filename to a profile, a PyCMSError is raised.

If an error occurs while trying to obtain the info tag, a PyCMSError is raised

Use this function to obtain the information stored in the profile’s info tag. This often contains details about the profile, and how it was created, as supplied by the creator.

参数:profile – EITHER a valid CmsProfile object, OR a string of the filename of an ICC profile.
返回:A string containing the internal profile information stored in an ICC tag.
引发 PyCMSError:
PIL.ImageCms.getProfileManufacturer(profile)[source]

(pyCMS) Gets the manufacturer for the given profile.

If profile isn’t a valid CmsProfile object or filename to a profile, a PyCMSError is raised.

If an error occurs while trying to obtain the manufacturer tag, a PyCMSError is raised

Use this function to obtain the information stored in the profile’s manufacturer tag.

参数:profile – EITHER a valid CmsProfile object, OR a string of the filename of an ICC profile.
返回:A string containing the internal profile information stored in an ICC tag.
引发 PyCMSError:
PIL.ImageCms.getProfileModel(profile)[source]

(pyCMS) Gets the model for the given profile.

If profile isn’t a valid CmsProfile object or filename to a profile, a PyCMSError is raised.

If an error occurs while trying to obtain the model tag, a PyCMSError is raised

Use this function to obtain the information stored in the profile’s model tag.

参数:profile – EITHER a valid CmsProfile object, OR a string of the filename of an ICC profile.
返回:A string containing the internal profile information stored in an ICC tag.
引发 PyCMSError:
PIL.ImageCms.getProfileName(profile)[source]

(pyCMS) Gets the internal product name for the given profile.

If profile isn’t a valid CmsProfile object or filename to a profile,

a PyCMSError is raised If an error occurs while trying to obtain the name tag, a PyCMSError is raised.

Use this function to obtain the INTERNAL name of the profile (stored in an ICC tag in the profile itself), usually the one used when the profile was originally created. Sometimes this tag also contains additional information supplied by the creator.

参数:profile – EITHER a valid CmsProfile object, OR a string of the filename of an ICC profile.
返回:A string containing the internal name of the profile as stored in an ICC tag.
引发 PyCMSError:
PIL.ImageCms.get_display_profile(handle=None)[source]

(experimental) Fetches the profile for the current display device. :returns: None if the profile is not known.

PIL.ImageCms.isIntentSupported(profile, intent, direction)[source]

(pyCMS) Checks if a given intent is supported.

Use this function to verify that you can use your desired renderingIntent with profile, and that profile can be used for the input/output/proof profile as you desire.

Some profiles are created specifically for one “direction”, can cannot
be used for others. Some profiles can only be used for certain

rendering intents... so it’s best to either verify this before trying to create a transform with them (using this function), or catch the potential PyCMSError that will occur if they don’t support the modes you select.

参数:
  • profile – EITHER a valid CmsProfile object, OR a string of the filename of an ICC profile.
  • intent

    Integer (0-3) specifying the rendering intent you wish to use with this profile

    INTENT_PERCEPTUAL = 0 (DEFAULT) (ImageCms.INTENT_PERCEPTUAL) INTENT_RELATIVE_COLORIMETRIC = 1 (ImageCms.INTENT_RELATIVE_COLORIMETRIC) INTENT_SATURATION = 2 (ImageCms.INTENT_SATURATION) INTENT_ABSOLUTE_COLORIMETRIC = 3 (ImageCms.INTENT_ABSOLUTE_COLORIMETRIC)

    see the pyCMS documentation for details on rendering intents and what they do.

  • direction

    Integer specifing if the profile is to be used for input, output, or proof

    INPUT = 0 (or use ImageCms.DIRECTION_INPUT) OUTPUT = 1 (or use ImageCms.DIRECTION_OUTPUT) PROOF = 2 (or use ImageCms.DIRECTION_PROOF)
返回:

1 if the intent/direction are supported, -1 if they are not.

引发 PyCMSError:

PIL.ImageCms.profileToProfile(im, inputProfile, outputProfile, renderingIntent=0, outputMode=None, inPlace=0, flags=0)[source]

(pyCMS) Applies an ICC transformation to a given image, mapping from inputProfile to outputProfile.

If the input or output profiles specified are not valid filenames, a PyCMSError will be raised. If inPlace == TRUE and outputMode != im.mode, a PyCMSError will be raised. If an error occurs during application of the profiles, a PyCMSError will be raised. If outputMode is not a mode supported by the outputProfile (or by pyCMS), a PyCMSError will be raised.

This function applies an ICC transformation to im from inputProfile’s color space to outputProfile’s color space using the specified rendering intent to decide how to handle out-of-gamut colors.

OutputMode can be used to specify that a color mode conversion is to be done using these profiles, but the specified profiles must be able to handle that mode. I.e., if converting im from RGB to CMYK using profiles, the input profile must handle RGB data, and the output profile must handle CMYK data.

参数:
  • im – An open PIL image object (i.e. Image.new(...) or Image.open(...), etc.)
  • inputProfile – String, as a valid filename path to the ICC input profile you wish to use for this image, or a profile object
  • outputProfile – String, as a valid filename path to the ICC output profile you wish to use for this image, or a profile object
  • renderingIntent

    Integer (0-3) specifying the rendering intent you wish to use for the transform

    INTENT_PERCEPTUAL = 0 (DEFAULT) (ImageCms.INTENT_PERCEPTUAL) INTENT_RELATIVE_COLORIMETRIC = 1 (ImageCms.INTENT_RELATIVE_COLORIMETRIC) INTENT_SATURATION = 2 (ImageCms.INTENT_SATURATION) INTENT_ABSOLUTE_COLORIMETRIC = 3 (ImageCms.INTENT_ABSOLUTE_COLORIMETRIC)

    see the pyCMS documentation for details on rendering intents and what they do.

  • outputMode – A valid PIL mode for the output image (i.e. “RGB”, “CMYK”, etc.). Note: if rendering the image “inPlace”, outputMode MUST be the same mode as the input, or omitted completely. If omitted, the outputMode will be the same as the mode of the input image (im.mode)
  • inPlace – Boolean (1 = True, None or 0 = False). If True, the original image is modified in-place, and None is returned. If False (default), a new Image object is returned with the transform applied.
  • flags – Integer (0-...) specifying additional flags
返回:

Either None or a new PIL image object, depending on value of inPlace

引发 PyCMSError:

PIL.ImageCms.versions()[source]

(pyCMS) Fetches versions.

ImageDraw2 Module

class PIL.ImageDraw2.Brush(color, opacity=255)[source]
class PIL.ImageDraw2.Draw(image, size=None, color=None)[source]
arc(xy, start, end, *options)[source]
chord(xy, start, end, *options)[source]
ellipse(xy, *options)[source]
flush()[source]
line(xy, *options)[source]
pieslice(xy, start, end, *options)[source]
polygon(xy, *options)[source]
rectangle(xy, *options)[source]
render(op, xy, pen, brush=None)[source]
settransform(offset)[source]
symbol(xy, symbol, *options)[source]
text(xy, text, font)[source]
textsize(text, font)[source]
class PIL.ImageDraw2.Font(color, file, size=12)[source]
class PIL.ImageDraw2.Pen(color, width=1, opacity=255)[source]

ImageFileIO Module

The ImageFileIO module can be used to read an image from a socket, or any other stream device.

Deprecated. New code should use the PIL.ImageFile.Parser class in the PIL.ImageFile module instead.

也可以参考

modules PIL.ImageFile.Parser

class PIL.ImageFileIO.ImageFileIO(fp)[source]

Bases: _io.BytesIO

ImageShow Module

class PIL.ImageShow.DisplayViewer[source]

Bases: PIL.ImageShow.UnixViewer

get_command_ex(file, **options)[source]
class PIL.ImageShow.UnixViewer[source]

Bases: PIL.ImageShow.Viewer

show_file(file, **options)[source]
class PIL.ImageShow.Viewer[source]
format = None
get_command(file, **options)[source]
get_format(image)[source]
save_image(image)[source]
show(image, **options)[source]
show_file(file, **options)[source]
show_image(image, **options)[source]
class PIL.ImageShow.XVViewer[source]

Bases: PIL.ImageShow.UnixViewer

get_command_ex(file, title=None, **options)[source]
PIL.ImageShow.register(viewer, order=1)[source]
PIL.ImageShow.show(image, title=None, **options)[source]
PIL.ImageShow.which(executable)[source]

ImageTransform Module

class PIL.ImageTransform.AffineTransform(data)[source]

Bases: PIL.ImageTransform.Transform

method = 0
class PIL.ImageTransform.ExtentTransform(data)[source]

Bases: PIL.ImageTransform.Transform

method = 1
class PIL.ImageTransform.MeshTransform(data)[source]

Bases: PIL.ImageTransform.Transform

method = 4
class PIL.ImageTransform.QuadTransform(data)[source]

Bases: PIL.ImageTransform.Transform

method = 3
class PIL.ImageTransform.Transform(data)[source]

Bases: PIL.Image.ImageTransformHandler

getdata()[source]
transform(size, image, **options)[source]

JpegPresets Module

JPEG quality settings equivalent to the Photoshop settings.

More presets can be added to the presets dict if needed.

Can be use when saving JPEG file.

To apply the preset, specify:

quality="preset_name"

To apply only the quantization table:

qtables="preset_name"

To apply only the subsampling setting:

subsampling="preset_name"

Example:

im.save("image_name.jpg", quality="web_high")

Subsampling

Subsampling is the practice of encoding images by implementing less resolution for chroma information than for luma information. (ref.: http://en.wikipedia.org/wiki/Chroma_subsampling)

Possible subsampling values are 0, 1 and 2 that correspond to 4:4:4, 4:2:2 and 4:1:1 (or 4:2:0?).

You can get the subsampling of a JPEG with the JpegImagePlugin.get_subsampling(im) function.

Quantization tables

They are values use by the DCT (Discrete cosine transform) to remove unnecessary information from the image (the lossy part of the compression). (ref.: http://en.wikipedia.org/wiki/Quantization_matrix#Quantization_matrices, http://en.wikipedia.org/wiki/JPEG#Quantization)

You can get the quantization tables of a JPEG with:

im.quantization

This will return a dict with a number of arrays. You can pass this dict directly as the qtables argument when saving a JPEG.

The tables format between im.quantization and quantization in presets differ in 3 ways:

  1. The base container of the preset is a list with sublists instead of dict. dict[0] -> list[0], dict[1] -> list[1], ...
  2. Each table in a preset is a list instead of an array.
  3. The zigzag order is remove in the preset (needed by libjpeg >= 6a).

You can convert the dict format to the preset format with the JpegImagePlugin.convert_dict_qtables(dict_qtables) function.

Libjpeg ref.: http://www.jpegcameras.com/libjpeg/libjpeg-3.html

OleFileIO Module

OleFileIO_PL: Module to read Microsoft OLE2 files (also called Structured Storage or Microsoft Compound Document File Format), such as Microsoft Office documents, Image Composer and FlashPix files, Outlook messages, ... This version is compatible with Python 2.6+ and 3.x

version 0.30 2014-02-04 Philippe Lagadec - http://www.decalage.info

Project website: http://www.decalage.info/python/olefileio

Improved version of the OleFileIO module from PIL library v1.1.6 See: http://www.pythonware.com/products/pil/index.htm

The Python Imaging Library (PIL) is
Copyright (c) 1997-2005 by Secret Labs AB Copyright (c) 1995-2005 by Fredrik Lundh

OleFileIO_PL changes are Copyright (c) 2005-2014 by Philippe Lagadec

See source code and LICENSE.txt for information on usage and redistribution.

WARNING: THIS IS (STILL) WORK IN PROGRESS.

class PIL.OleFileIO.OleFileIO(filename=None, raise_defects=40)[source]

OLE container object

This class encapsulates the interface to an OLE 2 structured storage file. Use the {@link listdir} and {@link openstream} methods to access the contents of this file.

Object names are given as a list of strings, one for each subentry level. The root entry should be omitted. For example, the following code extracts all image streams from a Microsoft Image Composer file:

ole = OleFileIO("fan.mic")

for entry in ole.listdir():
    if entry[1:2] == "Image":
        fin = ole.openstream(entry)
        fout = open(entry[0:1], "wb")
        while True:
            s = fin.read(8192)
            if not s:
                break
            fout.write(s)

You can use the viewer application provided with the Python Imaging Library to view the resulting files (which happens to be standard TIFF files).

close()[source]

close the OLE file, to release the file object

dumpdirectory()[source]

Dump directory (for debugging only)

dumpfat(fat, firstindex=0)[source]

Displays a part of FAT in human-readable form for debugging purpose

dumpsect(sector, firstindex=0)[source]

Displays a sector in a human-readable form, for debugging purpose.

exists(filename)[source]

Test if given filename exists as a stream or a storage in the OLE container.

filename: path of stream in storage tree. (see openstream for syntax) return: True if object exist, else False.

get_metadata()[source]

Parse standard properties streams, return an OleMetadata object containing all the available metadata. (also stored in the metadata attribute of the OleFileIO object)

new in version 0.25

get_rootentry_name()[source]

Return root entry name. Should usually be ‘Root Entry’ or ‘R’ in most implementations.

get_size(filename)[source]

Return size of a stream in the OLE container, in bytes.

filename: path of stream in storage tree (see openstream for syntax) return: size in bytes (long integer) raise: IOError if file not found, TypeError if this is not a stream.

get_type(filename)[source]

Test if given filename exists as a stream or a storage in the OLE container, and return its type.

filename: path of stream in storage tree. (see openstream for syntax) return: False if object does not exist, its entry type (>0) otherwise:

  • STGTY_STREAM: a stream
  • STGTY_STORAGE: a storage
  • STGTY_ROOT: the root entry
getctime(filename)[source]

Return creation time of a stream/storage.

filename: path of stream/storage in storage tree. (see openstream for syntax) return: None if creation time is null, a python datetime object otherwise (UTC timezone)

new in version 0.26

getmtime(filename)[source]

Return modification time of a stream/storage.

filename: path of stream/storage in storage tree. (see openstream for syntax) return: None if modification time is null, a python datetime object otherwise (UTC timezone)

new in version 0.26

getproperties(filename, convert_time=False, no_conversion=None)[source]

Return properties described in substream.

filename: path of stream in storage tree (see openstream for syntax) convert_time: bool, if True timestamps will be converted to Python datetime no_conversion: None or list of int, timestamps not to be converted

(for example total editing time is not a real timestamp)

return: a dictionary of values indexed by id (integer)

getsect(sect)[source]

Read given sector from file on disk. sect: sector index returns a string containing the sector data.

listdir(streams=True, storages=False)[source]

Return a list of streams stored in this file

streams: bool, include streams if True (True by default) - new in v0.26 storages: bool, include storages if True (False by default) - new in v0.26 (note: the root storage is never included)

loaddirectory(sect)[source]

Load the directory. sect: sector index of directory stream.

loadfat(header)[source]

Load the FAT table.

loadfat_sect(sect)[source]

Adds the indexes of the given sector to the FAT sect: string containing the first FAT sector, or array of long integers return: index of last FAT sector.

loadminifat()[source]

Load the MiniFAT table.

open(filename)[source]

Open an OLE2 file. Reads the header, FAT and directory.

filename: string-like or file-like object

openstream(filename)[source]

Open a stream as a read-only file object (BytesIO).

filename: path of stream in storage tree (except root entry), either:
  • a string using Unix path syntax, for example: ‘storage_1/storage_1.2/stream’
  • a list of storage filenames, path to the desired stream/storage. Example: [‘storage_1’, ‘storage_1.2’, ‘stream’]

return: file object (read-only) raise IOError if filename not found, or if this is not a stream.

sect2array(sect)[source]

convert a sector to an array of 32 bits unsigned integers, swapping bytes on big endian CPUs such as PowerPC (old Macs)

PIL.OleFileIO.isOleFile(filename)[source]

Test if file is an OLE container (according to its header). filename: file name or path (str, unicode) return: True if OLE, False otherwise.

PaletteFile Module

class PIL.PaletteFile.PaletteFile(fp)[source]
getpalette()[source]
rawmode = 'RGB'

PcfFontFile Module

class PIL.PcfFontFile.PcfFontFile(fp)[source]

Bases: PIL.FontFile.FontFile

name = 'name'
PIL.PcfFontFile.sz(s, o)[source]

TarIO Module

class PIL.TarIO.TarIO(tarfile, file)[source]

Bases: PIL.ContainerIO.ContainerIO

TiffTags Module

WalImageFile Module

PIL.WalImageFile.open(filename)[source]

_binary Module

PIL._binary.i16be(c, o=0)[source]
PIL._binary.i16le(c, o=0)[source]

Converts a 2-bytes (16 bits) string to an integer.

c: string containing bytes to convert o: offset of bytes to convert in string

PIL._binary.i32be(c, o=0)[source]
PIL._binary.i32le(c, o=0)[source]

Converts a 4-bytes (32 bits) string to an integer.

c: string containing bytes to convert o: offset of bytes to convert in string

PIL._binary.i8(c)[source]
PIL._binary.o16be(i)[source]
PIL._binary.o16le(i)[source]
PIL._binary.o32be(i)[source]
PIL._binary.o32le(i)[source]
PIL._binary.o8(i)[source]