English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

PHP Basic Tutorial

PHP Advanced Tutorial

PHP & MySQL

PHP Reference Manual

PHP imagecolorclosesthwb() How to use and examples of getting the closest shade index of the specified color

PHP Image Processing

imagecolorclosesthwb — Get the index of the closest shade of the specified color.

Syntax

int imagecolorclosesthwb ( resource $image , int $red , int $green , int $blue )

Get the index of the closest shade of the given color.

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

Parameter

  • imageImage resource returned by the image creation function (such as imagecreatetruecolor()).

  • redValue of the red component.

  • greenValue of the green component.

  • blueValue of the blue component.

Return Value

Returns an integer, which is the index of the closest shade of the given color.

Example

<?php
$im = imagecreatefromgif('php.gif');
echo 'HWB: ' . imagecolorclosesthwb($im, 116, 115, 152);
imagedestroy($im);
?>

The output of the above example is similar to:

HWB: 33

Related Articles

PHP Image Processing