PHP 8.6.0 Beta 3 is available for testing

Imagick::setImageType

(PECL imagick 2, PECL imagick 3)

Imagick::setImageTypeConfigure le type d'image

Description

public function Imagick::setImageType(int $image_type): bool

Convertit l'image vers le type donné, qui combine un modèle colorimétrique et la présence ou l'absence d'un canal alpha. Selon le type, cela peut changer l'espace colorimétrique, quantifier les couleurs, ou modifier la présence d'un canal alpha sur l'image.

Imagick::setImageType() modifie l'image elle-même. Pour définir à la place le type avec lequel les images suivantes seront écrites, utiliser Imagick::setType().

Liste de paramètres

image_type

Une des constantes imagick::IMGTYPE_*. imagick::IMGTYPE_UNDEFINED et imagick::IMGTYPE_OPTIMIZE ne convertissent rien, mais sont tout de même enregistrées sur l'image.

Valeurs de retour

Retourne true en cas de succès.

add a note

User Contributed Notes 3 notes

up
2
quickshiftin at gmail dot com
11 years ago
The cleaner way to set the type to grayscale is to use the Imagick class constant.

$oBw = new \Imagick($sSourceImage);
$oBw->setImageType(\Imagick::IMGTYPE_GRAYSCALE);

I've found this to be a rather harsh 'convert to grayscale' approach. Fred's color2gray script works much better, but it's written in Bash. Time to get it ported over lol

http://www.fmwconcepts.com/imagemagick/color2gray/index.php
up
1
Simon J
6 years ago
The different image types that can be specified are (from the Imagick::getImageType doc page):

    Imagick::IMGTYPE_UNDEFINED
    Imagick::IMGTYPE_BILEVEL
    Imagick::IMGTYPE_GRAYSCALE
    Imagick::IMGTYPE_GRAYSCALEMATTE
    Imagick::IMGTYPE_PALETTE
    Imagick::IMGTYPE_PALETTEMATTE
    Imagick::IMGTYPE_TRUECOLOR
    Imagick::IMGTYPE_TRUECOLORMATTE
    Imagick::IMGTYPE_COLORSEPARATION
    Imagick::IMGTYPE_COLORSEPARATIONMATTE
    Imagick::IMGTYPE_OPTIMIZE

The MATTE variants are equivalent to GrayscaleAlpha, etc. in the ImageMagick command line. If you're making something grayscale, I would recommend using IMGTYPE_GRAYSCALEMATTE.

<?php

$im->setImageType(Imagick::IMGTYPE_GRAYSCALEMATTE);

?>
up
0
lee dot traynor at skeptic dot de
14 years ago
This function can be used to desaturate an image, i.e. to convert a coloured image into a greyscale:

<?php

$im = new Imagick ("image.jpg");
$im->setImageType (2);
//is now in 256 shades of grey

?>
To Top