imagecolorexact

(PHP 4, PHP 5, PHP 7, PHP 8)

imagecolorexactDevuelve el índice del color especificado

Descripción

imagecolorexact(
    GdImage $image,
    int $red,
    int $green,
    int $blue
): int

Devuelve el índice del color especificado en la paleta de la imagen image.

If you created the image from a file, only colors used in the image are resolved. Colors present only in the palette are not resolved.

Parámetros

image

Un objeto GdImage, retornado por una de las funciones de creación de imágenes, como imagecreatetruecolor().

red

Value of red component.

green

Value of green component.

blue

Value of blue component.

Valores devueltos

Devuelve el índice del color especificado en la paleta, o -1 si el color no existe.

Historial de cambios

Versión Descripción
8.0.0 image expects a GdImage instance now; previously, a valid gd resource was expected.

Ejemplos

Ejemplo #1 Obtención de los colores que componen el logo GD

<?php
// Define la imagen
$im = imagecreatefrompng('./gdlogo.png');

$colors = Array();
$colors[] = imagecolorexact($im, 255, 0, 0);
$colors[] = imagecolorexact($im, 0, 0, 0);
$colors[] = imagecolorexact($im, 255, 255, 255);
$colors[] = imagecolorexact($im, 100, 255, 52);

print_r($colors);
?>

Resultado del ejemplo anterior es similar a :

Array
(
    [0] => 16711680
    [1] => 0
    [2] => 16777215
    [3] => 6618932
)

Ver también