note 63629 added to function.imagesetpixel
| From: | i | Date: | Sun, 26 Mar 2006 09:20:14 +0000 |
| Subject: | note 63629 added to function.imagesetpixel | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-106624@lists.php.net to get a copy of this message | ||
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/
----
Server IP: 84.18.202.180
Probable Submitter: 84.9.161.115
----
X-Spam-Status: No, hits=3.1 required=5.0 tests=DATE_MISSING,FROM_NO_LOWER
autolearn=no version=2.64
----
Manual Page -- http://www.php.net/manual/en/function.imagesetpixel.php
Edit -- http://master.php.net/note/edit/63629
Del: integrated -- http://master.php.net/note/delete/63629/integrated
Del: useless -- http://master.php.net/note/delete/63629/useless
Del: bad code -- http://master.php.net/note/delete/63629/bad+code
Del: spam -- http://master.php.net/note/delete/63629/spam
Del: non-english -- http://master.php.net/note/delete/63629/non-english
Del: in docs -- http://master.php.net/note/delete/63629/in+docs
Del: other reasons-- http://master.php.net/note/delete/63629
Reject -- http://master.php.net/note/reject/63629
Search -- http://master.php.net/manage/user-notes.php