note 102004 added to function.imagefill
| From: | EduardResina at osu1 dot php dot net | Date: | Sat, 22 Jan 2011 15:12:15 +0000 |
| Subject: | note 102004 added to function.imagefill | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-176003@lists.php.net to get a copy of this message | ||
Using imagefill with alpha colors in a png file does not allow for blending the filling with the
original image. On the other hand, substituting imagefill with imagefilledrectangle in order to fill
with alpha colors is only helpful when a rectangle shape is desired. This example shows how to
imagefill with alpha color or alpha tile images allowing the existing background of the original
image to come through, and yet filling only the area with the same color surrounding the filling
start point.
<?php
$fillstartx = 30;
$fillstarty = 80;
$r = 180;
$g = 200;
$b = 60;
$alpha = 80;
$tileimage = null;
$mainimage = imagecreatefrompng("myimage.png");
$intermediateimage = imagecreatefrompng("myimage.png"); //intermediate copy
$imagewidth = imagesx($mainimage);
$imageheight = imagesy($mainimage);
/* $tileimage = imagecreatefrompng("tile.png"); //FOR TILE IMAGEFILL */
if ($tileimage) {
imagesettile($intermediateimage, $tileimage);
$color = IMG_COLOR_TILED;
}
else $color = imagecolorallocatealpha($intermediateimage, $r, $g, $b, $alpha);
imagealphablending($intermediateimage, false);
imagefill($intermediateimage, $fillstartx, $fillstarty, $color);
imagesettile($mainimage, $intermediateimage); //set the filled copy as a tile to the main image
imagealphablending($mainimage, true);
imagefilledrectangle($mainimage, 0, 0, $imagewidth, $imageheight, IMG_COLOR_TILED); //apply the tile
copy on top of the original
imagealphablending($mainimage, false);
imagesavealpha($mainimage, true);
imagepng($mainimage, "myimage.png", 0);
imagedestroy($intermediateimage);
imagedestroy($mainimage);
?>
----
Server IP: 69.147.83.197
Probable Submitter: 79.144.171.120
----
Manual Page -- http://www.php.net/manual/en/function.imagefill.php
Edit -- https://master.php.net/note/edit/102004
Del: integrated -- https://master.php.net/note/delete/102004/integrated
Del: useless -- https://master.php.net/note/delete/102004/useless
Del: bad code -- https://master.php.net/note/delete/102004/bad+code
Del: spam -- https://master.php.net/note/delete/102004/spam
Del: non-english -- https://master.php.net/note/delete/102004/non-english
Del: in docs -- https://master.php.net/note/delete/102004/in+docs
Del: other reasons-- https://master.php.net/note/delete/102004
Reject -- https://master.php.net/note/reject/102004
Search -- https://master.php.net/manage/user-notes.php