syrkull
syrkull

Reputation: 2344

get the first pixel from the image using 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?

Upvotes: 3

Views: 2740

Answers (1)

ZombieSpy
ZombieSpy

Reputation: 1376

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

Upvotes: 10

Related Questions