Jump to content

php image & pixel manipulation


jake2891

Recommended Posts

Hey guys im tring to write a script for a challenge and im a little stuck. I need to read the pixels of an image and if the pixel is white get its position. Below is my code i think the problem is in my $chk part any ideas?

 

list($width, $height) = getimagesize('./test.png');

 

$image = imagecreatefrompng('./test.png');

$ascii = array();

 

$i = 0;

for($row=0;$row<$height;$row++){

  for($column=0;$column<$width;$column++){

      $pos = imagecolorat($image,$row,$column);

      $chk = ($pos & 0xFFFFFF);

      if($chk){

        $ascii[] = $i;

        $i = 0;

      }else{

        $i++;

      }

  }

}

 

$convert = array();

foreach($ascii as $asc){

  $convert[] = chr($asc);

 

}

print_r($convert);

 

Link to comment
https://forums.phpfreaks.com/topic/135137-php-image-pixel-manipulation/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.