Easy Tutorial
❮ Func Simplexml Getname Php Is_String Function ❯

PHP imagecolorresolvealpha - Get the index of the specified color with transparency or the closest possible alternative

PHP Image Processing

imagecolorresolvealpha — Get the index of the specified color with transparency or the closest possible alternative.

Syntax

int imagecolorresolvealpha ( resource $image , int $red , int $green , int $blue , int $alpha )

This function guarantees to return a color index for the requested color, either the exact value or the closest possible alternative.

Note: This function requires GD 2.0.1 or higher (recommended 2.0.28 and higher).

Parameters

The color parameters are integers between 0 and 255, or hexadecimal numbers between 0x00 and 0xFF.

Return Value

Returns a color index.

Example

Get colors from the tutorialpro.org logo.

<?php
// Create an image
$im = imagecreatefrompng('tutorialpro-logo.png');

// Get the closest colors from the image
$colors = array();
$colors[] = imagecolorresolvealpha($im, 255, 255, 255, 0);
$colors[] = imagecolorresolvealpha($im, 0, 0, 200, 127);

// Output
print_r($colors);

imagedestroy($im);
?>

The output of the above example is similar to:

Array
(
    [0] => 16777215
    [1] => 2130706632
)

Related Articles

PHP Image Processing

❮ Func Simplexml Getname Php Is_String Function ❯