imagecolorresolve() function in PHP


The imagecolorresolve() function gets the index of the specified color or its closest possible alternative.

Syntax

imagecolorresolve (img , red , green , blue )

Parameters

  • img: Image created with imagecreatetruecolor() function.

  • red: The value of red component.

  • green: The value of green component.

  • blue: The value of blue component.

Return

The imagecolorresolve() function returns the color index.

Example

The following is an example

 Live Demo

<?php
   $img = imagecreatefromgif('https://www.tutorialspoint.com/images/html.gif');
   $colors = array();
   $colors[] = imagecolorresolve($img, 120, 0, 190);
   $colors[] = imagecolorresolve($img, 110, 0, 140);
   $colors[] = imagecolorresolve($img, 120, 190, 0);
   print_r($colors);
   imagedestroy($img);
?>

Output

The following is the output:

Array ( [0] => 128 [1] => 129 [2] => 130 )

Updated on: 31-Dec-2019

16 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements