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

How do you match the character ^ at the beginning of the string? - ^^

1 Answers  


Do you know what are traits?

0 Answers  


i am a php programmer can i be a java programmer?

3 Answers  


What does $globals mean?

0 Answers  


Explain the difference between require() and require_once()?

0 Answers  






How can I embed a java programme in PHP file and what changes have to be done in PHP.ini file?

1 Answers   Sify, Small Biz Express,


How to print \ in php. Only \ with out using . or *.

7 Answers   American Solutions,


Write a function that takes "depth" as argument and return sum of node's data of that depth. For instance, (0) depth 0 / \ (10) (20) depth 1 / \ (40) (50) depth2 If I pass get_sum_by_depth(2) , it would return 90 (i.e. 40 + 50 )

0 Answers   Amazon,


What are PHP Magic Methods/Functions. List them.

0 Answers  


How can we extract string "pcds.co.in" from a string "https://info@pcds.co.in" using regular expression of php? More on reg can you explain

0 Answers  


Can we use include (?abc.PHP?) two times in a PHP page ?makeit.PHP??

5 Answers  


Which is correct about mysqli and pdo?

0 Answers  


Categories