lopes_andre Posted July 19, 2010 Share Posted July 19, 2010 Hi, I need to do something like this, but with GD, it is possible? http://eclecticdjs.com/mike/tutorials/php/imagemagick/examples_01/blackthreshold.php Given a colour, transform that colour to black. It is possible with GD? Best Regards, Quote Link to comment Share on other sites More sharing options...
lemmin Posted July 19, 2010 Share Posted July 19, 2010 Yeah, you can do that. You could iterate through each pixel with imagecolorat(). http://us.php.net/manual/en/function.imagecolorat.php Quote Link to comment Share on other sites More sharing options...
lopes_andre Posted July 19, 2010 Author Share Posted July 19, 2010 Thanks for the reply, I'am testing this code, but it is not working... <?php $img = imagecreatefromjpeg("image2.jpg"); $w = imagesx($img); $h = imagesy($img); for($y=0;$y<$h;$y++) { for($x=0;$x<$w;$x++) { $rgb = imagecolorat($img, $x, $y); imagecolorset($img, $rgb, 0, 0, 255); } } ?> Any clue? Best Regards, Quote Link to comment Share on other sites More sharing options...
Alex Posted July 19, 2010 Share Posted July 19, 2010 That code will loop through every color and change that color to blue. Making the entire image blue. Try something like: $img = imagecreatefromjpeg("image2.jpg"); $rgb = imagecolorat($img, $x, $y); // replace $x and $y here to be the point you want.. imagecolorset($img, $rgb, 0, 0, 255); You're also not outputting the new image to see the changes. Add this to the end of the script: header('Content-type: image/jpeg'); imagejpeg($img); imagejpeg Quote Link to comment Share on other sites More sharing options...
lopes_andre Posted July 19, 2010 Author Share Posted July 19, 2010 Thanks for the reply, I'am testing with both codes, but the codes don't do anything... <?php $img = imagecreatefromjpeg("image2.jpg"); $w = imagesx($img); $h = imagesy($img); for($y=0;$y<$h;$y++) { for($x=0;$x<$w;$x++) { $rgb = imagecolorat($img, $x, $y); imagecolorset($img, $rgb, 0, 0, 0); } } imagejpeg($img, 'simpleimg.jpg'); ?> Any clue? Best Regards, Quote Link to comment Share on other sites More sharing options...
lopes_andre Posted July 19, 2010 Author Share Posted July 19, 2010 Any clue on what might be wrong on the code? Best Regards, Quote Link to comment Share on other sites More sharing options...
Alex Posted July 19, 2010 Share Posted July 19, 2010 Did you change the $x and $y to the x and y of the pixel containing the color that you want to replace? Quote Link to comment Share on other sites More sharing options...
lopes_andre Posted July 20, 2010 Author Share Posted July 20, 2010 Did you change the $x and $y to the x and y of the pixel containing the color that you want to replace? Yes, I have changed, but didn't see any change, so I put the code in the FOR Loops, but no changes in the image. Some clue on what could be wrong? Best Regards, Quote Link to comment Share on other sites More sharing options...
Alex Posted July 20, 2010 Share Posted July 20, 2010 It should work as long as you're inputting the correct information. The script should look something like this: $img = imagecreatefromjpeg("image2.jpg"); $rgb = imagecolorat($img, $x, $y); // replace $x and $y here to be the point you want.. imagecolorset($img, $rgb, 0, 0, 255); header('Content-type: image/jpeg'); imagejpeg($img); That would take image2.jpg and take whatever color is at point ($x, $y) and replace it throughout the whole image with blue, and then display it in the browser. Quote Link to comment Share on other sites More sharing options...
lopes_andre Posted July 20, 2010 Author Share Posted July 20, 2010 Hi, Thanks for the reply. I'am seeing the result with the above code, so I have tried with: <?php $img = imagecreatefromjpeg("image2.jpg"); $w = imagesx($img); $h = imagesy($img); for($y=0;$y<$h;$y++) { for($x=0;$x<$w;$x++) { $rgb = imagecolorat($img, $x, $y); imagecolorset($img, $rgb, 0, 0, 0); } } imagejpeg($img, 'simpleimg.jpg'); ?> Unfortunately it is not working. Some clue? Quote Link to comment Share on other sites More sharing options...
Alex Posted July 20, 2010 Share Posted July 20, 2010 $img = imagecreatefromjpeg("image2.jpg"); $rgb = imagecolorat($img, $x, $y); // replace $x and $y here to be the point you want.. imagecolorset($img, $rgb, 0, 0, 255); header('Content-type: image/jpeg'); imagejpeg($img, 'simpleimg.jpg'); Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.