ImagickPixel::getColorValue

(PECL imagick 2, PECL imagick 3)

ImagickPixel::getColorValueBelirtilen renk kanalının normalleştirilmiş değerini döndürür

Açıklama

public ImagickPixel::getColorValue(int $kanal): float

Belirtilen renk kanalının değerini 0 ile 1 arasında bir gerçek sayı olarak döndürür.

Bağımsız Değişkenler

kanal

Normalde kanal türü sabitlerinden biri.

Dönen Değerler

Belirtilen renk kanalının değerini 0 ile 1 arasında bir gerçek sayı olarak döndürür. Bir hata durumunda bir ImagickPixelException yavrulanır.

Örnekler

Örnek 1 - Imagick::getColorValue() temel kullanım örneği

<?php

$color
= new ImagickPixel('rgba(90%, 20%, 20%, 0.75)');

echo
"Matlık: ".$color->getColorValue(Imagick::COLOR_ALPHA).PHP_EOL;
echo
"".PHP_EOL;
echo
Kırmızı: ".$color->getColorValue(Imagick::COLOR_RED).PHP_EOL;
echo "
Yeşil: ".$color->getColorValue(Imagick::COLOR_GREEN).PHP_EOL;
echo "
Mavi: ".$color->getColorValue(Imagick::COLOR_BLUE).PHP_EOL;
echo "".PHP_EOL;
echo "
Turkuaz: ".$color->getColorValue(Imagick::COLOR_CYAN).PHP_EOL;
echo "
Mor: ".$color->getColorValue(Imagick::COLOR_MAGENTA).PHP_EOL;
echo "
Sarı: ".$color->getColorValue(Imagick::COLOR_YELLOW).PHP_EOL;
echo "
Siyah: ".$color->getColorValue(Imagick::COLOR_BLACK).PHP_EOL;

?>

Yukarıdaki örneğin çıktısı:

Matlık: 0.74999618524453

Kırmızı: 0.90000762951095
Yeşil: 0.2
Mavi: 0.2

Turkuaz: 0.90000762951095
Mor: 0.2
Sarı: 0.2
Siyah: 0

add a note add a note

User Contributed Notes 3 notes

up
0
Anonymous
4 years ago
COLOR_ALPHA - not fully transparent pixel
COLOR_OPACITY - completely transparent pixel
up
0
holdoffhunger at gmail dot com
12 years ago
When getting a color value back with getColorValue, you are free to use any color scheme: either the Red/Green/Blue (RGB) scheme or the Cyan/Magenta/Yellow/blacK (CMYK) scheme.  For RGB, this function works with the constant values of "COLOR_RED", "COLOR_GREEN", and "COLOR_BLUE," and for CMYK, this function works with the constant values of "COLOR_CYAN", "COLOR_MAGENTA", "COLOR_YELLOW", and "COLOR_BLACK".  As a programmer, the main question you're probably asking yourself is "How do I know if one pixel's color is different from the others?"  That seems to be defined as a unique combination of RGB *or* CMYK values.  Each RGB set of values with have a unique set of CMYK values for only that set of RGB values, so an RGB of 1/0.5/0.5 with have a unique set of CMYK values, shared only by the other pixels of the same exact RGB values.

Why the CMYK?  Because that is the standard for printing, or to quote the Imagick site, "As such for printing we use four colored inks: Cyan, Magenta, Yellow, and blacK; and define images using these inks, to form a CMYK color space."  By being a "color space", you get the choice of working with either RGB or CMYK when defining a pixel as being unique among a set of pixels.  But you are completely free to go with either RGB or CMYK.  For more on it from the Imagick Site:

http://www.imagemagick.org/Usage/color_basics/

Some code that demonstrates both methods: (for a purple-ish red pixel)

<?php

       
// Grab Pixel
        // ---------------------------------------------------

   
$pixel_one = $imagick_type->getImagePixelColor(0,0);

       
// Grab Alpha/Opacity Values
        // ---------------------------------------------------
   
   
$pixel_one_color_value_alpha = $pixel_one->getColorValue(imagick::COLOR_ALPHA);
   
$pixel_one_color_value_opacity = $pixel_one->getColorValue(imagick::COLOR_OPACITY);

       
// Grab Red/Green/Blue (RGB) Values
        // ---------------------------------------------------
   
   
$pixel_one_color_value_red = $pixel_one->getColorValue(imagick::COLOR_RED);
   
$pixel_one_color_value_green = $pixel_one->getColorValue(imagick::COLOR_GREEN);
   
$pixel_one_color_value_blue = $pixel_one->getColorValue(imagick::COLOR_BLUE);

       
// Grab Cyna/Magenta/Yellow/blacK (CMYK) Values
        // ---------------------------------------------------
   
   
$pixel_one_color_value_cyan = $pixel_one->getColorValue(imagick::COLOR_CYAN);
   
$pixel_one_color_value_magenta = $pixel_one->getColorValue(imagick::COLOR_MAGENTA);
   
$pixel_one_color_value_yellow = $pixel_one->getColorValue(imagick::COLOR_YELLOW);
   
$pixel_one_color_value_black = $pixel_one->getColorValue(imagick::COLOR_BLACK);

       
// Print Results
        // ---------------------------------------------------
   
   
print("Alpha: $pixel_one_color_value_alpha<br>");
    print(
"Opacity: $pixel_one_color_value_opacity<br><br>");

    print(
"---------------------------------------------<br><br>");
   
    print(
"Red: $pixel_one_color_value_red<br>");
    print(
"Green: $pixel_one_color_value_green<br>");
    print(
"Blue: $pixel_one_color_value_blue<br><br>");
   
    print(
"Cyan: $pixel_one_color_value_cyan<br>");
    print(
"Magenta: $pixel_one_color_value_magenta<br>");
    print(
"Yellow: $pixel_one_color_value_yellow<br>");
    print(
"Black: $pixel_one_color_value_black<br><br>");

   
/*
            Example Results : : :
            -----------------------

Alpha: 1
Opacity: 0

---------------------------------------------

Red: 1
Green: 0.501960784314
Blue: 0.501960784314

Cyan: 1
Magenta: 0.501960784314
Yellow: 0.501960784314
Black: 0

    */

?>
up
0
mwwaygoo AT hotmail DOT com
14 years ago
QUOTE: $color   The channel to check, specified as one of the Imagick channel constants.

$color is a COLOR_* constant, not a channel constant

e.g.
<?php
$image
=new Imagick();
$image->readImage('test.png');
$point=$image->getImagePixelColor(0,0);
echo
' Alpha:'.$point->getColorValue(imagick::COLOR_ALPHA);
echo
' Opacity:'.$point->getColorValue(imagick::COLOR_OPACITY);
echo
' R:'.$point->getColorValue(imagick::COLOR_RED);
echo
' G:'.$point->getColorValue(imagick::COLOR_GREEN);
echo
' B:'.$point->getColorValue(imagick::COLOR_BLUE);
?>
To Top