PHP Conference Nagoya 2025

Imagick::getImageChannelDepth

(PECL imagick 2, PECL imagick 3)

Imagick::getImageChannelDepthObtiene la profundidad de un canal de imagen en particular

Descripción

public Imagick::getImageChannelDepth(int $channel): int

Obtiene la profundidad de un canal de imagen en particular.

Parámetros

channel

Proporciona cualquier contante de canal que sea válida para su modo de canal. Para aplicarlo a más de un canal, combine constantes de canal using bitwise operadores bit a bit. El valor por defecto para Imagick::CHANNEL_DEFAULT. Referirse a esta lista de constantes de canal

Valores devueltos

Devuelve true en caso de éxito.

add a note

User Contributed Notes 1 note

up
1
holdoffhunger at gmail dot com
12 years ago
For undocumented functions, this is a particular oddity. For me, this function has so far returned only two values for any particular image: 1 and 8. And, after experimenting with it about forty or fifty times, I think I understand how it works, based simply on my experience.

The value returned is the number of bits used for the particular color channel within an image. That means how variable a particular color is within an image. While I received 1 and 8, it could theoretically be as much as 16 or 32, depending on how the technology evolves over, say, the next decade or so.

To best understand this function, you should probably also understand the ImageMagick function getColorValue. In terms of the ImageMagick class, a color can be measured between 0 and 1, in terms in of a particular pixel. Red, Green, Blue, or, any particular color of any color scheme, can be something like 0.501960784314. But, since each pixel is a combination of the three colors, you can have 0.845 for red, 0.254 for green, and 0.11 for blue.

How does this all tie in with the getChannelDepth function? Easy. If all of the pixels in an image are either values 1 or values 0 for the particular Red/Green/Blue values, then this function will return a 1 for 1 bits per pixel for that color channel. If, however, any single pixel in the image for the inputted channel parameter isn't exactly 1 or 0 for the particular color channel, then this function will return an 8 for 8-bit colors per pixel for that color channel.

If you receive back a 1 for every single color channel put in the parameter, that means you're dealing with an image that's 16-bit -- you know, like those computer games published in 1982, or the Atari console games. You won't ever forget a 16-bit color green, trust me. If you get back an 8 for every single color channel put in the parameter, that means you're dealing with any standard, modern image.

You can input any color channel, based on the channel constants available within the ImageMagick class. See them here: http://www.php.net/manual/en/imagick.constants.php#imagick.constants.channel . That means a format like imagick::CHANNEL_UNDEFINED, but with the "_UNDEFINED" value being anything here: undefined, red, gray, cyan, green, magenta, blue, yellow, alpha, opacity, matte, black, index, all, and default.

For any image with one pixel color of RGB value 1 / 0.501960784314 / 0.501960784314 (#FF8080), you get this result:

Channel - 'Undefined' : 1
Channel - 'Red' : 1
Channel - 'Gray' : 1
Channel - 'Cyan' : 1
Channel - 'Green' : 8
Channel - 'Magenta' : 8
Channel - 'Blue' : 8
Channel - 'Yellow' : 8
Channel - 'Alpha' : 1
Channel - 'Opacity' : 1
Channel - 'Matte' : 1
Channel - 'Black' : 1
Channel - 'Index' : 1
Channel - 'All' : 8
Channel - 'Default' : 8

If all colors are between 0 and 1 with getColorValue function, each of these results with be 1. If you're dealing with an image that has full color spectrum depth (almost any given photograph), you'll get 8 for red, gray, cyan, green, magenta, blue, yellow, all, and default, with a 1 for the other remaining channels. Perhaps some use for automated image editing, like use with posterize or oilpaint functions.
To Top