Movatterモバイル変換


[0]ホーム

URL:


ContentsMenuExpandLight modeDark modeAuto light/dark, in light modeAuto light/dark, in dark modeSkip to content
Pillow (PIL Fork) 12.0.0 documentation
Light LogoDark Logo
Pillow (PIL Fork) 12.0.0 documentation
Back to top

ImageCms module

TheImageCms module provides color profile managementsupport using the LittleCMS2 color management engine, based on KevinCazabon’s PyCMS library.

classPIL.ImageCms.ImageCmsProfile(profile:str|SupportsRead[bytes]|CmsProfile)[source]
__init__(profile:str|SupportsRead[bytes]|CmsProfile)None[source]
Parameters:

profile – Either a string representing a filename,a file like object containing a profile or alow-level profile object

tobytes()bytes[source]

Returns the profile in a format suitable for embedding insaved images.

Returns:

a bytes object containing the ICC profile.

classPIL.ImageCms.ImageCmsTransform(input:~PIL.ImageCms.ImageCmsProfile,output:~PIL.ImageCms.ImageCmsProfile,input_mode:str,output_mode:str,intent:~PIL.ImageCms.Intent=Intent.PERCEPTUAL,proof:~PIL.ImageCms.ImageCmsProfile|None=None,proof_intent:~PIL.ImageCms.Intent=Intent.ABSOLUTE_COLORIMETRIC,flags:~PIL.ImageCms.Flags=<Flags.NONE:0>)[source]

Bases:ImagePointHandler

Transform. This can be used with the procedural API, or with the standardpoint() method.

Will return the output profile in theoutput.info['icc_profile'].

apply(im:Image,imOut:Image|None=None)Image[source]
apply_in_place(im:Image)Image[source]
point(im:Image)Image[source]
exceptionPIL.ImageCms.PyCMSError[source]

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

Constants

classPIL.ImageCms.Intent(*values)[source]

Bases:IntEnum

PERCEPTUAL=0
RELATIVE_COLORIMETRIC=1
SATURATION=2
ABSOLUTE_COLORIMETRIC=3
classPIL.ImageCms.Direction(*values)[source]

Bases:IntEnum

INPUT=0
OUTPUT=1
PROOF=2
classPIL.ImageCms.Flags(*values)[source]

Bases:IntFlag

Flags and documentation are taken fromlcms2.h.

NONE=0
NOCACHE=64

Inhibit 1-pixel cache

NOOPTIMIZE=256

Inhibit optimizations

NULLTRANSFORM=512

Don’t transform anyway

GAMUTCHECK=4096

Out of Gamut alarm

SOFTPROOFING=16384

Do softproofing

BLACKPOINTCOMPENSATION=8192
NOWHITEONWHITEFIXUP=4

Don’t fix scum dot

HIGHRESPRECALC=1024

Use more memory to give better accuracy

LOWRESPRECALC=2048

Use less memory to minimize resources

USE_8BITS_DEVICELINK=8

Create 8 bits devicelinks

GUESSDEVICECLASS=32

Guess device class (fortransform2devicelink)

KEEP_SEQUENCE=128

Keep profile sequence for devicelink creation

FORCE_CLUT=2

Force CLUT optimization

CLUT_POST_LINEARIZATION=1

create postlinearization tables if possible

CLUT_PRE_LINEARIZATION=16

create prelinearization tables if possible

NONEGATIVES=32768

Prevent negative numbers in floating point transforms

COPY_ALPHA=67108864

Alpha channels are copied oncmsDoTransform()

NODEFAULTRESOURCEDEF=16777216
staticGRIDPOINTS(n:int)Flags[source]

Fine-tune control over number of gridpoints

Parameters:

nint in range0<=n<=255

Functions

PIL.ImageCms.applyTransform(im:Image,transform:ImageCmsTransform,inPlace:bool=False)Image|None[source]

(pyCMS) Applies a transform to a given image.

Ifim.mode!=transform.input_mode, aPyCMSError is raised.

IfinPlace isTrue andtransform.input_mode!=transform.output_mode, aPyCMSError is raised.

Ifim.mode,transform.input_mode ortransform.output_mode is notsupported by pyCMSdll or the profiles you used for the transform, aPyCMSError is raised.

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

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

If you want to modify im in-place instead of receiving a new image asthe return value, setinPlace toTrue. This can only be done iftransform.input_mode andtransform.output_mode are the same, because wecan’t change the mode in-place (the buffer sizes for some modes aredifferent). The default behavior is to return a newImageobject of the same dimensions in modetransform.output_mode.

Parameters:
  • im – AnImage object, andim.mode must be the sameas theinput_mode supported by the transform.

  • transform – A valid CmsTransform class object

  • inPlace – Bool. IfTrue,im is modified in place andNone isreturned, ifFalse, a newImage object with thetransform applied is returned (andim is not changed). The default isFalse.

Returns:

EitherNone, or a newImage object,depending on the value ofinPlace. The profile will be returned inthe image’sinfo['icc_profile'].

Raises:

PyCMSError

PIL.ImageCms.buildProofTransform(inputProfile:str|~PIL._typing.SupportsRead[bytes]|~PIL.ImageCms.core.CmsProfile|~PIL.ImageCms.ImageCmsProfile,outputProfile:str|~PIL._typing.SupportsRead[bytes]|~PIL.ImageCms.core.CmsProfile|~PIL.ImageCms.ImageCmsProfile,proofProfile:str|~PIL._typing.SupportsRead[bytes]|~PIL.ImageCms.core.CmsProfile|~PIL.ImageCms.ImageCmsProfile,inMode:str,outMode:str,renderingIntent:~PIL.ImageCms.Intent=Intent.PERCEPTUAL,proofRenderingIntent:~PIL.ImageCms.Intent=Intent.ABSOLUTE_COLORIMETRIC,flags:~PIL.ImageCms.Flags=<Flags.SOFTPROOFING:16384>)ImageCmsTransform[source]

(pyCMS) Builds an ICC transform mapping from theinputProfile to theoutputProfile, but tries to simulate the result that would beobtained on theproofProfile device.

If the input, output, or proof profiles specified are not validfilenames, aPyCMSError will be raised.

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

IfinMode oroutMode are not a mode supported by theoutputProfile(or by pyCMS), aPyCMSError will be raised.

This function builds and returns an ICC transform from theinputProfileto theoutputProfile, but tries to simulate the result that would beobtained on theproofProfile device usingrenderingIntent andproofRenderingIntent to determine what to do with out-of-gamutcolors. This is known as “soft-proofing”. It will ONLY work forconverting images that are ininMode to images that are in outModecolor format (PIL mode, i.e. “RGB”, “RGBA”, “CMYK”, etc.).

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

Proof profiling is generally used when using an output device to get agood idea of what the final printed/displayed image would look like ontheproofProfile device when it’s quicker and easier to use theoutput device for judging color. Generally, this means that theoutput device is a monitor, or a dye-sub printer (etc.), and the simulateddevice 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 theoutput device to match the colors of the device being simulated. However,when the simulated device has a much wider gamut than the outputdevice, you may obtain marginal results.

Parameters:
  • inputProfile – String, as a valid filename path to the ICC inputprofile 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 aprofile object

  • proofProfile – String, as a valid filename path to the ICC proofprofile you wish to use for this transform, or a profile object

  • inMode – String, as a valid PIL mode that the appropriate profilealso supports (i.e. “RGB”, “RGBA”, “CMYK”, etc.)

  • outMode – String, as a valid PIL mode that the appropriate profilealso supports (i.e. “RGB”, “RGBA”, “CMYK”, etc.)

  • renderingIntent

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

    ImageCms.Intent.PERCEPTUAL = 0 (DEFAULT)ImageCms.Intent.RELATIVE_COLORIMETRIC = 1ImageCms.Intent.SATURATION = 2ImageCms.Intent.ABSOLUTE_COLORIMETRIC = 3

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

  • proofRenderingIntent

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

    ImageCms.Intent.PERCEPTUAL = 0 (DEFAULT)ImageCms.Intent.RELATIVE_COLORIMETRIC = 1ImageCms.Intent.SATURATION = 2ImageCms.Intent.ABSOLUTE_COLORIMETRIC = 3

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

  • flags – Integer (0-…) specifying additional flags

Returns:

A CmsTransform class object.

Raises:

PyCMSError

PIL.ImageCms.buildProofTransformFromOpenProfiles(inputProfile:str|~PIL._typing.SupportsRead[bytes]|~PIL.ImageCms.core.CmsProfile|~PIL.ImageCms.ImageCmsProfile,outputProfile:str|~PIL._typing.SupportsRead[bytes]|~PIL.ImageCms.core.CmsProfile|~PIL.ImageCms.ImageCmsProfile,proofProfile:str|~PIL._typing.SupportsRead[bytes]|~PIL.ImageCms.core.CmsProfile|~PIL.ImageCms.ImageCmsProfile,inMode:str,outMode:str,renderingIntent:~PIL.ImageCms.Intent=Intent.PERCEPTUAL,proofRenderingIntent:~PIL.ImageCms.Intent=Intent.ABSOLUTE_COLORIMETRIC,flags:~PIL.ImageCms.Flags=<Flags.SOFTPROOFING:16384>)ImageCmsTransform

(pyCMS) Builds an ICC transform mapping from theinputProfile to theoutputProfile, but tries to simulate the result that would beobtained on theproofProfile device.

If the input, output, or proof profiles specified are not validfilenames, aPyCMSError will be raised.

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

IfinMode oroutMode are not a mode supported by theoutputProfile(or by pyCMS), aPyCMSError will be raised.

This function builds and returns an ICC transform from theinputProfileto theoutputProfile, but tries to simulate the result that would beobtained on theproofProfile device usingrenderingIntent andproofRenderingIntent to determine what to do with out-of-gamutcolors. This is known as “soft-proofing”. It will ONLY work forconverting images that are ininMode to images that are in outModecolor format (PIL mode, i.e. “RGB”, “RGBA”, “CMYK”, etc.).

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

Proof profiling is generally used when using an output device to get agood idea of what the final printed/displayed image would look like ontheproofProfile device when it’s quicker and easier to use theoutput device for judging color. Generally, this means that theoutput device is a monitor, or a dye-sub printer (etc.), and the simulateddevice 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 theoutput device to match the colors of the device being simulated. However,when the simulated device has a much wider gamut than the outputdevice, you may obtain marginal results.

Parameters:
  • inputProfile – String, as a valid filename path to the ICC inputprofile 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 aprofile object

  • proofProfile – String, as a valid filename path to the ICC proofprofile you wish to use for this transform, or a profile object

  • inMode – String, as a valid PIL mode that the appropriate profilealso supports (i.e. “RGB”, “RGBA”, “CMYK”, etc.)

  • outMode – String, as a valid PIL mode that the appropriate profilealso supports (i.e. “RGB”, “RGBA”, “CMYK”, etc.)

  • renderingIntent

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

    ImageCms.Intent.PERCEPTUAL = 0 (DEFAULT)ImageCms.Intent.RELATIVE_COLORIMETRIC = 1ImageCms.Intent.SATURATION = 2ImageCms.Intent.ABSOLUTE_COLORIMETRIC = 3

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

  • proofRenderingIntent

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

    ImageCms.Intent.PERCEPTUAL = 0 (DEFAULT)ImageCms.Intent.RELATIVE_COLORIMETRIC = 1ImageCms.Intent.SATURATION = 2ImageCms.Intent.ABSOLUTE_COLORIMETRIC = 3

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

  • flags – Integer (0-…) specifying additional flags

Returns:

A CmsTransform class object.

Raises:

PyCMSError

PIL.ImageCms.buildTransform(inputProfile:str|~PIL._typing.SupportsRead[bytes]|~PIL.ImageCms.core.CmsProfile|~PIL.ImageCms.ImageCmsProfile,outputProfile:str|~PIL._typing.SupportsRead[bytes]|~PIL.ImageCms.core.CmsProfile|~PIL.ImageCms.ImageCmsProfile,inMode:str,outMode:str,renderingIntent:~PIL.ImageCms.Intent=Intent.PERCEPTUAL,flags:~PIL.ImageCms.Flags=<Flags.NONE:0>)ImageCmsTransform[source]

(pyCMS) Builds an ICC transform mapping from theinputProfile to theoutputProfile. Use applyTransform to apply the transform to a givenimage.

If the input or output profiles specified are not valid filenames, aPyCMSError will be raised. If an error occurs during creationof the transform, aPyCMSError will be raised.

IfinMode oroutMode are not a mode supported by theoutputProfile(or by pyCMS), aPyCMSError will be raised.

This function builds and returns an ICC transform from theinputProfileto theoutputProfile using therenderingIntent to determine what to dowith out-of-gamut colors. It will ONLY work for converting images thatare ininMode to images that are inoutMode color format (PIL mode,i.e. “RGB”, “RGBA”, “CMYK”, etc.).

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

The reason pyCMS returns a class object rather than a handle directlyto the transform is that it needs to keep track of the PIL input/outputmodes that the transform is meant for. These attributes are stored intheinMode andoutMode attributes of the object (which can bemanually overridden if you really want to, but I don’t know of anytime that would be of use, or would even work).

Parameters:
  • inputProfile – String, as a valid filename path to the ICC inputprofile you wish to use for this transform, or a profile object

  • outputProfile – String, as a valid filename path to the ICC outputprofile you wish to use for this transform, or a profile object

  • inMode – String, as a valid PIL mode that the appropriate profilealso supports (i.e. “RGB”, “RGBA”, “CMYK”, etc.)

  • outMode – String, as a valid PIL mode that the appropriate profilealso supports (i.e. “RGB”, “RGBA”, “CMYK”, etc.)

  • renderingIntent

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

    ImageCms.Intent.PERCEPTUAL = 0 (DEFAULT)ImageCms.Intent.RELATIVE_COLORIMETRIC = 1ImageCms.Intent.SATURATION = 2ImageCms.Intent.ABSOLUTE_COLORIMETRIC = 3

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

  • flags – Integer (0-…) specifying additional flags

Returns:

A CmsTransform class object.

Raises:

PyCMSError

PIL.ImageCms.buildTransformFromOpenProfiles(inputProfile:str|~PIL._typing.SupportsRead[bytes]|~PIL.ImageCms.core.CmsProfile|~PIL.ImageCms.ImageCmsProfile,outputProfile:str|~PIL._typing.SupportsRead[bytes]|~PIL.ImageCms.core.CmsProfile|~PIL.ImageCms.ImageCmsProfile,inMode:str,outMode:str,renderingIntent:~PIL.ImageCms.Intent=Intent.PERCEPTUAL,flags:~PIL.ImageCms.Flags=<Flags.NONE:0>)ImageCmsTransform

(pyCMS) Builds an ICC transform mapping from theinputProfile to theoutputProfile. Use applyTransform to apply the transform to a givenimage.

If the input or output profiles specified are not valid filenames, aPyCMSError will be raised. If an error occurs during creationof the transform, aPyCMSError will be raised.

IfinMode oroutMode are not a mode supported by theoutputProfile(or by pyCMS), aPyCMSError will be raised.

This function builds and returns an ICC transform from theinputProfileto theoutputProfile using therenderingIntent to determine what to dowith out-of-gamut colors. It will ONLY work for converting images thatare ininMode to images that are inoutMode color format (PIL mode,i.e. “RGB”, “RGBA”, “CMYK”, etc.).

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

The reason pyCMS returns a class object rather than a handle directlyto the transform is that it needs to keep track of the PIL input/outputmodes that the transform is meant for. These attributes are stored intheinMode andoutMode attributes of the object (which can bemanually overridden if you really want to, but I don’t know of anytime that would be of use, or would even work).

Parameters:
  • inputProfile – String, as a valid filename path to the ICC inputprofile you wish to use for this transform, or a profile object

  • outputProfile – String, as a valid filename path to the ICC outputprofile you wish to use for this transform, or a profile object

  • inMode – String, as a valid PIL mode that the appropriate profilealso supports (i.e. “RGB”, “RGBA”, “CMYK”, etc.)

  • outMode – String, as a valid PIL mode that the appropriate profilealso supports (i.e. “RGB”, “RGBA”, “CMYK”, etc.)

  • renderingIntent

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

    ImageCms.Intent.PERCEPTUAL = 0 (DEFAULT)ImageCms.Intent.RELATIVE_COLORIMETRIC = 1ImageCms.Intent.SATURATION = 2ImageCms.Intent.ABSOLUTE_COLORIMETRIC = 3

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

  • flags – Integer (0-…) specifying additional flags

Returns:

A CmsTransform class object.

Raises:

PyCMSError

PIL.ImageCms.createProfile(colorSpace:Literal['LAB','XYZ','sRGB'],colorTemp:SupportsFloat=0)CmsProfile[source]

(pyCMS) Creates a profile.

If colorSpace not in["LAB","XYZ","sRGB"],aPyCMSError is raised.

If using LAB andcolorTemp is not a positive integer,aPyCMSError is raised.

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

Use this function to create common profiles on-the-fly instead ofhaving to supply a profile on disk and knowing the path to it. Itreturns a normal CmsProfile object that can be passed toImageCms.buildTransformFromOpenProfiles() to create a transform to applyto images.

Parameters:
  • colorSpace – String, the color space of the profile you wish tocreate.Currently only “LAB”, “XYZ”, and “sRGB” are supported.

  • colorTemp – Positive number for the white point for the profile, indegrees Kelvin (i.e. 5000, 6500, 9600, etc.). The default is for D50illuminant if omitted (5000k). colorTemp is ONLY applied to LABprofiles, and is ignored for XYZ and sRGB.

Returns:

A CmsProfile class object

Raises:

PyCMSError

PIL.ImageCms.getDefaultIntent(profile:str|SupportsRead[bytes]|CmsProfile|ImageCmsProfile)int[source]

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

Ifprofile isn’t a valid CmsProfile object or filename to a profile, aPyCMSError is raised.

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

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

Parameters:

profile – EITHER a valid CmsProfile object, OR a string of thefilename of an ICC profile.

Returns:

Integer 0-3 specifying the default rendering intent for thisprofile.

ImageCms.Intent.PERCEPTUAL = 0 (DEFAULT)ImageCms.Intent.RELATIVE_COLORIMETRIC = 1ImageCms.Intent.SATURATION = 2ImageCms.Intent.ABSOLUTE_COLORIMETRIC = 3

see the pyCMS documentation for details on rendering intents and what

they do.

Raises:

PyCMSError

PIL.ImageCms.getOpenProfile(profileFilename:str|SupportsRead[bytes]|CmsProfile)ImageCmsProfile[source]

(pyCMS) Opens an ICC profile file.

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

IfprofileFilename is not a valid filename for an ICC profile,aPyCMSError will be raised.

Parameters:

profileFilename – String, as a valid filename path to the ICC profileyou wish to open, or a file-like object.

Returns:

A CmsProfile class object.

Raises:

PyCMSError

PIL.ImageCms.getProfileCopyright(profile:str|SupportsRead[bytes]|CmsProfile|ImageCmsProfile)str[source]

(pyCMS) Gets the copyright for the given profile.

Ifprofile isn’t a valid CmsProfile object or filename to a profile, aPyCMSError is raised.

If an error occurs while trying to obtain the copyright tag,aPyCMSError is raised.

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

Parameters:

profile – EITHER a valid CmsProfile object, OR a string of thefilename of an ICC profile.

Returns:

A string containing the internal profile information stored inan ICC tag.

Raises:

PyCMSError

PIL.ImageCms.getProfileDescription(profile:str|SupportsRead[bytes]|CmsProfile|ImageCmsProfile)str[source]

(pyCMS) Gets the description for the given profile.

Ifprofile isn’t a valid CmsProfile object or filename to a profile, aPyCMSError is raised.

If an error occurs while trying to obtain the description tag,aPyCMSError is raised.

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

Parameters:

profile – EITHER a valid CmsProfile object, OR a string of thefilename of an ICC profile.

Returns:

A string containing the internal profile information stored in anICC tag.

Raises:

PyCMSError

PIL.ImageCms.getProfileInfo(profile:str|SupportsRead[bytes]|CmsProfile|ImageCmsProfile)str[source]

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

Ifprofile isn’t a valid CmsProfile object or filename to a profile,aPyCMSError is raised.

If an error occurs while trying to obtain the info tag,aPyCMSError is raised.

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

Parameters:

profile – EITHER a valid CmsProfile object, OR a string of thefilename of an ICC profile.

Returns:

A string containing the internal profile information stored inan ICC tag.

Raises:

PyCMSError

PIL.ImageCms.getProfileManufacturer(profile:str|SupportsRead[bytes]|CmsProfile|ImageCmsProfile)str[source]

(pyCMS) Gets the manufacturer for the given profile.

Ifprofile isn’t a valid CmsProfile object or filename to a profile, aPyCMSError is raised.

If an error occurs while trying to obtain the manufacturer tag, aPyCMSError is raised.

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

Parameters:

profile – EITHER a valid CmsProfile object, OR a string of thefilename of an ICC profile.

Returns:

A string containing the internal profile information stored inan ICC tag.

Raises:

PyCMSError

PIL.ImageCms.getProfileModel(profile:str|SupportsRead[bytes]|CmsProfile|ImageCmsProfile)str[source]

(pyCMS) Gets the model for the given profile.

Ifprofile isn’t a valid CmsProfile object or filename to a profile, aPyCMSError is raised.

If an error occurs while trying to obtain the model tag,aPyCMSError is raised.

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

Parameters:

profile – EITHER a valid CmsProfile object, OR a string of thefilename of an ICC profile.

Returns:

A string containing the internal profile information stored inan ICC tag.

Raises:

PyCMSError

PIL.ImageCms.getProfileName(profile:str|SupportsRead[bytes]|CmsProfile|ImageCmsProfile)str[source]

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

Ifprofile isn’t a valid CmsProfile object or filename to a profile,aPyCMSError is raised If an error occurs while tryingto obtain the name tag, aPyCMSError is raised.

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

Parameters:

profile – EITHER a valid CmsProfile object, OR a string of thefilename of an ICC profile.

Returns:

A string containing the internal name of the profile as storedin an ICC tag.

Raises:

PyCMSError

PIL.ImageCms.get_display_profile(handle:SupportsInt|None=None)ImageCmsProfile|None[source]

(experimental) Fetches the profile for the current display device.

Returns:

None if the profile is not known.

PIL.ImageCms.isIntentSupported(profile:str|SupportsRead[bytes]|CmsProfile|ImageCmsProfile,intent:Intent,direction:Direction)Literal[-1,1][source]

(pyCMS) Checks if a given intent is supported.

Use this function to verify that you can use your desiredintent withprofile, and thatprofile can be used for theinput/output/proof profile as you desire.

Some profiles are created specifically for one “direction”, can cannotbe used for others. Some profiles can only be used for certainrendering intents, so it’s best to either verify this before tryingto create a transform with them (using this function), or catch thepotentialPyCMSError that will occur if they don’tsupport the modes you select.

Parameters:
  • profile – EITHER a valid CmsProfile object, OR a string of thefilename of an ICC profile.

  • intent

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

    ImageCms.Intent.PERCEPTUAL = 0 (DEFAULT)ImageCms.Intent.RELATIVE_COLORIMETRIC = 1ImageCms.Intent.SATURATION = 2ImageCms.Intent.ABSOLUTE_COLORIMETRIC = 3

    see the pyCMS documentation for details on rendering intents and what

    they do.

  • direction

    Integer specifying if the profile is to be used forinput, output, or proof

    INPUT = 0 (or use ImageCms.Direction.INPUT)OUTPUT = 1 (or use ImageCms.Direction.OUTPUT)PROOF = 2 (or use ImageCms.Direction.PROOF)

Returns:

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

Raises:

PyCMSError

PIL.ImageCms.profileToProfile(im:~PIL.Image.Image,inputProfile:str|~PIL._typing.SupportsRead[bytes]|~PIL.ImageCms.core.CmsProfile|~PIL.ImageCms.ImageCmsProfile,outputProfile:str|~PIL._typing.SupportsRead[bytes]|~PIL.ImageCms.core.CmsProfile|~PIL.ImageCms.ImageCmsProfile,renderingIntent:~PIL.ImageCms.Intent=Intent.PERCEPTUAL,outputMode:str|None=None,inPlace:bool=False,flags:~PIL.ImageCms.Flags=<Flags.NONE:0>)Image|None[source]

(pyCMS) Applies an ICC transformation to a given image, mapping frominputProfile tooutputProfile.

If the input or output profiles specified are not valid filenames, aPyCMSError will be raised. IfinPlace isTrue andoutputMode!=im.mode, aPyCMSError will be raised.If an error occurs during application of the profiles,aPyCMSError will be raised.IfoutputMode is not a mode supported by theoutputProfile (or by pyCMS),aPyCMSError will be raised.

This function applies an ICC transformation to im frominputProfile’scolor space tooutputProfile’s color space using the specified renderingintent to decide how to handle out-of-gamut colors.

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

Parameters:
  • im – An openImage object (i.e. Image.new(…)or Image.open(…), etc.)

  • inputProfile – String, as a valid filename path to the ICC inputprofile you wish to use for this image, or a profile object

  • outputProfile – String, as a valid filename path to the ICC outputprofile you wish to use for this image, or a profile object

  • renderingIntent

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

    ImageCms.Intent.PERCEPTUAL = 0 (DEFAULT)ImageCms.Intent.RELATIVE_COLORIMETRIC = 1ImageCms.Intent.SATURATION = 2ImageCms.Intent.ABSOLUTE_COLORIMETRIC = 3

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

  • outputMode – A valid PIL mode for the output image (i.e. “RGB”,“CMYK”, etc.). Note: if rendering the image “inPlace”, outputModeMUST be the same mode as the input, or omitted completely. Ifomitted, the outputMode will be the same as the mode of the inputimage (im.mode)

  • inPlace – Boolean. IfTrue, the original image is modified in-place,andNone is returned. IfFalse (default), a newImage object is returned with the transform applied.

  • flags – Integer (0-…) specifying additional flags

Returns:

Either None or a newImage object, depending onthe value ofinPlace

Raises:

PyCMSError

CmsProfile

The ICC color profiles are wrapped in an instance of the classCmsProfile. The specification ICC.1:2010 contains moreinformation about the meaning of the values in ICC profiles.

For convenience, all XYZ-values are also given as xyY-values (so theycan be easily displayed in a chromaticity diagram, for example).

classPIL.ImageCms.core.CmsProfile
creation_date:datetime.datetime|None

Date and time this profile was first created (see 7.2.1 of ICC.1:2010).

version:float

The version number of the ICC standard that this profile follows(e.g.2.0).

icc_version:int

Same asversion, but in encoded format (see 7.2.4 of ICC.1:2010).

device_class:str

4-character string identifying the profile class. One ofscnr,mntr,prtr,link,spac,abst,nmcl (see 7.2.5 of ICC.1:2010 for details).

xcolor_space:str

4-character string (padded with whitespace) identifying the colorspace, e.g.XYZ␣,RGB␣ orCMYK (see 7.2.6 ofICC.1:2010 for details).

connection_space:str

4-character string (padded with whitespace) identifying the colorspace on the B-side of the transform (see 7.2.7 of ICC.1:2010 fordetails).

header_flags:int

The encoded header flags of the profile (see 7.2.11 of ICC.1:2010for details).

header_manufacturer:str

4-character string (padded with whitespace) identifying the devicemanufacturer, which shall match the signature contained in theappropriate section of the ICC signature registry found atwww.color.org (see 7.2.12 of ICC.1:2010).

header_model:str

4-character string (padded with whitespace) identifying the devicemodel, which shall match the signature contained in theappropriate section of the ICC signature registry found atwww.color.org (see 7.2.13 of ICC.1:2010).

attributes:int

Flags used to identify attributes unique to the particular devicesetup for which the profile is applicable (see 7.2.14 ofICC.1:2010 for details).

rendering_intent:int

The rendering intent to use when combining this profile withanother profile (usually overridden at run-time, but provided herefor DeviceLink and embedded source profiles, see 7.2.15 of ICC.1:2010).

One ofImageCms.Intent.ABSOLUTE_COLORIMETRIC,ImageCms.Intent.PERCEPTUAL,ImageCms.Intent.RELATIVE_COLORIMETRIC andImageCms.Intent.SATURATION.

profile_id:bytes

A sequence of 16 bytes identifying the profile (via a speciallyconstructed MD5 sum), or 16 binary zeroes if the profile ID hasnot been calculated (see 7.2.18 of ICC.1:2010).

copyright:str|None

The text copyright information for the profile (see 9.2.21 of ICC.1:2010).

manufacturer:str|None

The (English) display string for the device manufacturer (see9.2.22 of ICC.1:2010).

model:str|None

The (English) display string for the device model of the devicefor which this profile is created (see 9.2.23 of ICC.1:2010).

profile_description:str|None

The (English) display string for the profile description (see9.2.41 of ICC.1:2010).

target:str|None

The name of the registered characterization data set, or themeasurement data for a characterization target (see 9.2.14 ofICC.1:2010).

red_colorant:tuple[tuple[float,float,float],tuple[float,float,float]]|None

The first column in the matrix used in matrix/TRC transforms (see 9.2.44 of ICC.1:2010).

The value is in the format((X,Y,Z),(x,y,Y)), if available.

green_colorant:tuple[tuple[float,float,float],tuple[float,float,float]]|None

The second column in the matrix used in matrix/TRC transforms (see 9.2.30 of ICC.1:2010).

The value is in the format((X,Y,Z),(x,y,Y)), if available.

blue_colorant:tuple[tuple[float,float,float],tuple[float,float,float]]|None

The third column in the matrix used in matrix/TRC transforms (see 9.2.4 of ICC.1:2010).

The value is in the format((X,Y,Z),(x,y,Y)), if available.

luminance:tuple[tuple[float,float,float],tuple[float,float,float]]|None

The absolute luminance of emissive devices in candelas per squaremetre as described by the Y channel (see 9.2.32 of ICC.1:2010).

The value is in the format((X,Y,Z),(x,y,Y)), if available.

chromaticity:tuple[tuple[float,float,float],tuple[float,float,float],tuple[float,float,float]]|None

The data of the phosphor/colorant chromaticity set used (red,green and blue channels, see 9.2.16 of ICC.1:2010).

The value is in the format((x,y,Y),(x,y,Y),(x,y,Y)), if available.

chromatic_adaption:tuple[tuple[tuple[float,float,float],tuple[float,float,float],tuple[float,float,float]],tuple[tuple[float,float,float],tuple[float,float,float],tuple[float,float,float]]]|None

The chromatic adaption matrix converts a color measured using theactual illumination conditions and relative to the actual adoptedwhite, to a color relative to the PCS adopted white, withcomplete adaptation from the actual adopted white chromaticity tothe PCS adopted white chromaticity (see 9.2.15 of ICC.1:2010).

Two 3-tuples of floats are returned in a 2-tuple,one in (X, Y, Z) space and one in (x, y, Y) space.

colorant_table:list[str]

This tag identifies the colorants used in the profile by a uniquename and set of PCSXYZ or PCSLAB values (see 9.2.19 ofICC.1:2010).

colorant_table_out:list[str]

This tag identifies the colorants used in the profile by a uniquename and set of PCSLAB values (for DeviceLink profiles only, see9.2.19 of ICC.1:2010).

colorimetric_intent:str|None

4-character string (padded with whitespace) identifying the imagestate of PCS colorimetry produced using the colorimetric intenttransforms (see 9.2.20 of ICC.1:2010 for details).

perceptual_rendering_intent_gamut:str|None

4-character string (padded with whitespace) identifying the (one)standard reference medium gamut (see 9.2.37 of ICC.1:2010 fordetails).

saturation_rendering_intent_gamut:str|None

4-character string (padded with whitespace) identifying the (one)standard reference medium gamut (see 9.2.37 of ICC.1:2010 fordetails).

technology:str|None

4-character string (padded with whitespace) identifying the devicetechnology (see 9.2.47 of ICC.1:2010 for details).

media_black_point:tuple[tuple[float,float,float],tuple[float,float,float]]|None

This tag specifies the media black point and is used forgenerating absolute colorimetry.

This tag was available in ICC 3.2, but it is removed fromversion 4.

The value is in the format((X,Y,Z),(x,y,Y)), if available.

media_white_point:tuple[tuple[float,float,float],tuple[float,float,float]]|None

This tag specifies the media white point and is used forgenerating absolute colorimetry.

The value is in the format((X,Y,Z),(x,y,Y)), if available.

media_white_point_temperature:float|None

Calculates the white point temperature (see the LCMS documentationfor more information).

viewing_condition:str|None

The (English) display string for the viewing conditions (see9.2.48 of ICC.1:2010).

screening_description:str|None

The (English) display string for the screening conditions.

This tag was available in ICC 3.2, but it is removed fromversion 4.

red_primary:tuple[tuple[float,float,float],tuple[float,float,float]]|None

The XYZ-transformed of the RGB primary color red (1, 0, 0).

The value is in the format((X,Y,Z),(x,y,Y)), if available.

green_primary:tuple[tuple[float,float,float],tuple[float,float,float]]|None

The XYZ-transformed of the RGB primary color green (0, 1, 0).

The value is in the format((X,Y,Z),(x,y,Y)), if available.

blue_primary:tuple[tuple[float,float,float],tuple[float,float,float]]|None

The XYZ-transformed of the RGB primary color blue (0, 0, 1).

The value is in the format((X,Y,Z),(x,y,Y)), if available.

is_matrix_shaper:bool

True if this profile is implemented as a matrix shaper (seedocumentation on LCMS).

clut:dict[int,tuple[bool,bool,bool]]|None

Returns a dictionary of all supported intents and directions forthe CLUT model.

The dictionary is indexed by intents(ImageCms.Intent.ABSOLUTE_COLORIMETRIC,ImageCms.Intent.PERCEPTUAL,ImageCms.Intent.RELATIVE_COLORIMETRIC andImageCms.Intent.SATURATION).

The values are 3-tuples indexed by directions(ImageCms.Direction.INPUT,ImageCms.Direction.OUTPUT,ImageCms.Direction.PROOF).

The elements of the tuple are booleans. If the value isTrue,that intent is supported for that direction.

intent_supported:dict[int,tuple[bool,bool,bool]]|None

Returns a dictionary of all supported intents and directions.

The dictionary is indexed by intents(ImageCms.Intent.ABSOLUTE_COLORIMETRIC,ImageCms.Intent.PERCEPTUAL,ImageCms.Intent.RELATIVE_COLORIMETRIC andImageCms.Intent.SATURATION).

The values are 3-tuples indexed by directions(ImageCms.Direction.INPUT,ImageCms.Direction.OUTPUT,ImageCms.Direction.PROOF).

The elements of the tuple are booleans. If the value isTrue,that intent is supported for that direction.

There is one function defined on the class:

is_intent_supported(intent:int,direction:int,/)

Returns if the intent is supported for the given direction.

Note that you can also get this information for all intents and directionswithintent_supported.

Parameters:
  • intent – One ofImageCms.Intent.ABSOLUTE_COLORIMETRIC,ImageCms.Intent.PERCEPTUAL,ImageCms.Intent.RELATIVE_COLORIMETRICandImageCms.Intent.SATURATION.

  • direction – One ofImageCms.Direction.INPUT,ImageCms.Direction.OUTPUTandImageCms.Direction.PROOF

Returns:

Boolean if the intent and direction is supported.

On this page

[8]ページ先頭

©2009-2025 Movatter.jp