3

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?

Community
  • 1
  • 1
syrkull
  • 2,295
  • 4
  • 35
  • 68
  • possible duplicate of [how can i get pixel value of image in php](http://stackoverflow.com/questions/15172115/how-can-i-get-pixel-value-of-image-in-php) – user Mar 22 '14 at 14:42

1 Answers1

10

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

ZombieSpy
  • 1,376
  • 12
  • 23