How can I find the colour of a pixel of an image?

Answers were Sorted based on User's Feedback



How can I find the colour of a pixel of an image? ..

Answer / laxmikant

<?php
$im = imagecreatefrompng("php.png");
$rgb = imagecolorat($im, 10, 15);
$r = ($rgb >> 16) & 0xFF;
$g = ($rgb >> 8) & 0xFF;
$b = $rgb & 0xFF;

var_dump($r, $g, $b);
?>

Is This Answer Correct ?    1 Yes 0 No

How can I find the colour of a pixel of an image? ..

Answer / jude jeevanraj.p

This is easily done through using the imagecolorat function.

You must pass as parameters the image resource, and the x
and y co-ordinates you want to find the color of, for
instance:

$rgb = imagecolorat($im, 5, 10);

Will get a reference to the colour used at 5,10 (X,Y) on
the image.

Depending on the version of the GD library you are using
and the type of image, you may experience different return
values

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More PHP Interview Questions

What difference between require() and require_once()?

0 Answers  


Which php framework is best for security?

0 Answers  


What is in php 7?

0 Answers  


Which method removes the last element from the end of an array?

0 Answers  


What is the use of strip_tags() method?

0 Answers  






Does php support multiple inheritances?

0 Answers  


How do you check if a variable has been set in php?

0 Answers  


How big is varchar max?

0 Answers  


What are Routines?

0 Answers  


Define metaphone()?

0 Answers  


what is the difference between ph4 and php5

2 Answers  


What are the different types of PHP arrays?

0 Answers  


Categories