imagecolorexact() function in PHP


The imagecolorexact() function gets the index of the specified color.

Syntax

imagecolorexact ( $img, $red, $green, $blue )

Parameters

  • img: Image resource created with imagecreatetruecolor().

  • red: Red color component

  • green: Green color component

  • blue: Blue color component

Return

The imagecolorexact() function returns the index of the specified color in the palette, or -1 if the color does not exist.

Example

The following is an example:

 Live Demo

<?php
   $img =    imagecreatefrompng('https://www.tutorialspoint.com/assets/videos/courses/67/images/course_67_image.png');
   $colors = Array();
   $colors[] = imagecolorexact($img, 30, 90, 50);
   $colors[] = imagecolorexact($img, 80, 120, 100);
   $colors[] = imagecolorexact($img, 25, 80, 50);
   print_r($colors);
   imagedestroy($img);
?>

Output

The following is the output:

Array ( [0] => 1989170 [1] => 5273700 [2] => 1658930 )

Updated on: 31-Dec-2019

45 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements