Board index   FAQ   Search  
Register  Login
Board index php forum :: php coding PHP coding => Images

imagesetpixel limits

images php coding issues or problems here.

Moderators: macek, egami, gesf

imagesetpixel limits

Postby Kyuzo » Sat Aug 13, 2011 10:59 am

Hi,
I wrote a code that pick all the pixels with a specific color from an image and set them in a blank image. But at a certain amount of pixels imagesetpixel() stops.
Can someone tell me why?

Code: Select all
<?php
if(isset($_POST["submit"])){
header("Content-Type: image/png");
$img = imagecreate(200, 100);
imagecolorallocate($img, 0, 0, 0);
$im = imagecreatefrompng("img.png");
$x = imagesx($im);
$y = imagesy($im);
for($i=0; $i<$x; $i++){
  for($j=0; $j<$y; $j++){
    $rgb = imagecolorsforindex($im, imagecolorat($im, $i, $j));
    if($rgb["red"]==$_POST["r1"] && $rgb["green"]==$_POST["g1"] && $rgb["blue"]==$_POST["b1"]){
      $s .= "$i,$j ";
      imagesetpixel($img, $i, $j, imagecolorallocate($img, $_POST["r1"], $_POST["g1"], $_POST["b1"]));
    }
    elseif($rgb["red"]==$_POST["r2"] && $rgb["green"]==$_POST["g2"] && $rgb["blue"]==$_POST["b2"]){
      $s2 .= "$i,$j ";
      //imagesetpixel($img, $i, $j, imagecolorallocate($img, $_POST["r2"], $_POST["g2"], $_POST["b2"]));
    }
  }
}
imagepng($img);
imagedestroy($img);
//print $s."\n".$s2;
}
else{
  print "<center><br /><br /><br /><br /><br /><form method=\"post\" action=\"\">Color 1 : <input type=\"text\" name=\"r1\" size=\"3\" value=\"73\" /><input type=\"text\" name=\"g1\" size=\"3\" value=\"167\" /><input type=\"text\" name=\"b1\" size=\"3\" value=\"248\" /><br />Color 2 : <input type=\"text\" name=\"r2\" size=\"3\" value=\"229\" /><input type=\"text\" name=\"g2\" size=\"3\" value=\"180\" /><input type=\"text\" name=\"b2\" size=\"3\" value=\"253\" /><br /><input type=\"submit\" name=\"submit\" /></form></center>";
}
?>


img.png : http://imageshack.us/photo/my-images/843/imgci.png/
Kyuzo
New php-forum User
New php-forum User
 
Posts: 2
Joined: Sat Aug 13, 2011 10:40 am

Re: imagesetpixel limits

Postby NigelRen » Sun Aug 14, 2011 10:05 am

Not sure if it makes a difference, but the image your creating as a target is set to 200x100, shouldn't this be done from the x & y dimensions of the source image?
NigelRen
php-forum Active User
php-forum Active User
 
Posts: 450
Joined: Fri Aug 05, 2011 9:53 am

Re: imagesetpixel limits

Postby Kyuzo » Sun Aug 14, 2011 4:15 pm

It is
Code: Select all
$x = imagesx($im);// 200
$y = imagesy($im);// 100
Kyuzo
New php-forum User
New php-forum User
 
Posts: 2
Joined: Sat Aug 13, 2011 10:40 am


Return to PHP coding => Images

Who is online

Users browsing this forum: No registered users and 2 guests

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.

cron