Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

get the first pixel from the image using php

Tags:

php

I am trying to get the first pixel of the image. preferably, the one very top left or right pixel. I saw this question and it has the closest answer to my question : Get image color

However, the answer only shows you how to get the average color. I do not want to get the average color, I want to get the first pixel from any side! anybody know of a way to do it?

like image 834
syrkull Avatar asked Jun 28 '26 10:06

syrkull


1 Answers

Try this, it gets the color of the top-left pixel (0,0):

<?php
    $im = imagecreatefrompng("image.png");
    $rgb = imagecolorat($im, 0, 0);

    $colors = imagecolorsforindex($im, $rgb);

    var_dump($colors);
?>

More info: http://php.net/manual/en/function.imagecolorat.php

like image 157
ZombieSpy Avatar answered Jun 30 '26 00:06

ZombieSpy