2

I have an image that is saved in a database. I need a script that can read the RGB + x and y value of each pixel of this image.

This is needed because I want to be able to show random pixels of this image in a browser. With random I mean, random positions. The number of pixels is selected with a form. When the form is used, a number of pixels of the image will be visible in the browser and this new image will be saved. The next time the form is used, the new image with a few pixels visible, will be displayed in the browser. And so on.... each time the form is used, the image will get more and more visible.

I did some testing with the PHP GD library, but not been able to extract the RGB as well as the position of each pixel. For outputting an array of RGBA vallues, I used this how to count number of pixels in image (php). But as you see, this is just the beginning.

$img = "images/test.png";
$imgHand = imagecreatefrompng("$img");
$imgSize = GetImageSize($img);
$imgWidth = $imgSize[0];
$imgHeight = $imgSize[1];


// Define a new array to store the info
$pxlCorArr= array();

for ($l = 0; $l < $imgHeight; $l++) {
    // Start a new "row" in the array for each row of the image.
    $pxlCorArr[$l] = array();

    for ($c = 0; $c < $imgWidth; $c++) {
        $pxlCor = ImageColorAt($imgHand,$c,$l);

        // Put each pixel's info in the array
        $pxlCorArr[$l][$c] = ImageColorsForIndex($imgHand, $pxlCor);
    }
}   
Community
  • 1
  • 1
BF_12
  • 21
  • 2

1 Answers1

1

do you want a partial image to be shown and then full image ? or random part of it ?

take a look at this ,

https://github.com/ogres/Image2HTML

it will convert an image to html table , you could edit it so only random part of image will be shown

ogres
  • 3,660
  • 1
  • 17
  • 16