ImagickPixel::getColor

(PECL imagick 2, PECL imagick 3)

ImagickPixel::getColorReturns the color

Description

public ImagickPixel::getColor(int $normalized = 0): array

Returns the color described by the ImagickPixel object, as an array. If the color has an opacity channel set, this is provided as a fourth value in the list.

Parameters

normalized

Normalize the color values. Possible values are 0, 1 or 2.

List of possible values for normalized
normalized Description
0 The RGB values are returned as ints in the range 0 to 255 (inclusive.) The alpha value is returned as int and is either 0 or 1.
1 The RGBA values are returned as floats in the range 0 to 1 (inclusive.)
2 The RGBA values are returned as ints in the range 0 to 255 (inclusive.)

Return Values

An array of channel values. Throws ImagickPixelException on error.

Examples

Example #1 Basic Imagick::getColor() usage

<?php

//Create an ImagickPixel with the predefined color 'brown'
$color = new ImagickPixel('brown');

//Set the color to have an alpha of 25%
$color->setColorValue(Imagick::COLOR_ALPHA64 256.0);

$colorInfo $color->getColor();

echo 
"Standard values".PHP_EOL;
print_r($colorInfo);

$colorInfo $color->getColor(1);

echo 
"Normalized values:".PHP_EOL;
print_r($colorInfo);

?>

The above example will output:

Standard values
Array
(
    [r] => 165
    [g] => 42
    [b] => 42
    [a] => 0
)
Normalized values:
Array
(
    [r] => 0.64705882352941
    [g] => 0.16470588235294
    [b] => 0.16470588235294
    [a] => 0.25000381475547
)
    

Here you can write a comment


Please enter at least 10 characters.
Loading... Please wait.
* Pflichtangabe
There are no comments available yet.

PHP cURL Tutorial: Using cURL to Make HTTP Requests

cURL is a powerful PHP extension that allows you to communicate with different servers using various protocols, including HTTP, HTTPS, FTP, and more. ...

TheMax

Autor : TheMax
Category: PHP-Tutorials

Midjourney Tutorial - Instructions for beginners

There is an informative video about Midjourney, the tool for creating digital images using artificial intelligence, entitled "Midjourney tutorial in German - instructions for beginners" ...

Mike94

Autor : Mike94
Category: KI Tutorials

Basics of views in MySQL

Views in a MySQL database offer the option of creating a virtual table based on the result of an SQL query. This virtual table can be queried like a normal table without changing the underlying data. ...

admin

Autor : admin
Category: mySQL-Tutorials

Publish a tutorial

Share your knowledge with other developers worldwide

Share your knowledge with other developers worldwide

You are a professional in your field and want to share your knowledge, then sign up now and share it with our PHP community

learn more

Publish a tutorial