php8.5
Home/ Manual/ imagick / imagick/ Imagick::transformImageColorspace

Imagick::transformImageColorspace

PHP function Edit on GitHub ✎

(PECL imagick 3)

Transforms an image to a new colorspace

Description

Imagick::transformImageColorspace(int $colorspace): bool

Transforms an image to a new colorspace.

Parameters

colorspace

The colorspace the image should be transformed to, one of the COLORSPACE constants e.g. Imagick::COLORSPACE_CMYK.

Return Values

Success

Examples

Imagick::transformImageColorspace example

Transforms an image to a new colorspace, and then extracts a single channel so that the individual channel values can be viewed.

php
<?php
function transformImageColorspace($imagePath, $colorSpace, $channel) {
    $imagick = new \Imagick(realpath($imagePath));
    $imagick->transformimagecolorspace($colorSpace);
    //channel should be one of the channel constants e.g. \Imagick::CHANNEL_BLUE 
    $imagick->separateImageChannel($channel);
    header("Content-Type: image/jpg");
    echo $imagick->getImageBlob();
}
?>

See Also

  • Imagick::setColorSpace

Source: reference/imagick/imagick/transformimagecolorspace.xml · from the official PHP manual (php/doc-en)