note 63629 deleted from function.imagesetpixel by nlopess

From: Date: Sun, 26 Mar 2006 19:00:53 +0000
Subject: note 63629 deleted from function.imagesetpixel by nlopess
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-106646@lists.php.net to get a copy of this message
Note Submitter: i [hyphen] am [at] wykis [bot] com ---- This functions is very useful if you want to replace a specific color with another color. This can be used the same way as str_replace, so i call it img_replace :) I wonder if there will be anything like img_preg_replace ;) <?php function img_replace($from,$to,&$im) { for ( $xx = 0; $xx < imagesx($im); $xx++ ) { for ( $yy = 0; $yy < imagesy($im); $yy++ ) { $cur=imagecolorat($im,$xx,$yy); if ( $cur == $from ) { imagesetpixel($im,$xx,$yy,$to); } } } } // Create a 500x500 image $image=imagecreatetruecolor(500,500); // Fill $col=imagecolorallocate($image,255,255,0); imagefilledrectangle( $image,0,0,imagesx($image), imagesy($image), $col ); // Print a red rectangle $col=imagecolorallocate($image,255,0,0); imagefilledrectangle($image,100,100,200,200,$col); // Replaces all Red to Bluish :) img_replace( imagecolorallocate($image,255,0,0), imagecolorallocate($image,0,100,255), $image ); header("Content-Type: image/png"); imagepng($image); ?> === http://wykis.com/

« previous php.notes (#106646) next »