note 108517 added to function.imagesetpixel
| From: | guy032 at gmail dot com | Date: | Thu, 03 May 2012 06:57:46 +0000 |
| Subject: | note 108517 added to function.imagesetpixel | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-187453@lists.php.net to get a copy of this message | ||
making images with white (or close to white) background transprent
<?
function FloodFill($im, $x, $y)
{
$rgb = imagecolorat($im, $x, $y);
$r = ($rgb >> 16) & 0xFF;
$g = ($rgb >> 8) & 0xFF;
$b = $rgb & 0xFF;
$counter=0;
$counter2=0;
if($r >= 245){ $counter++;}
if($g >= 245){ $counter++;}
if($b >= 245){ $counter++;}
if($r >= 240){ $counter2++;}
if($g >= 240){ $counter2++;}
if($b >= 240){ $counter2++;}
if($counter >= 1 && $counter2 == 3){
$background = imagecolorallocate($im, 180, 0, 255);
imagesetpixel($im, $x, $y, $background);
FloodFill ($im, $x, $y+1);
FloodFill ($im, $x+1, $y);
FloodFill ($im, $x, $y-1);
}
}
$src = $_GET["src"];
$im = imagecreatefromjpeg($src);
// Draw border
$border = imagecolorallocate($im, 180, 0, 255);
drawBorder($im, $border, 1);
// Draw a border
function drawBorder($im, $color, $thickness = 1)
{
$x1 = 0;
$y1 = 0;
$x2 = ImageSX($im) - 1;
$y2 = ImageSY($im) - 1;
for($i = 0; $i < $thickness; $i++)
{
ImageRectangle($im, $x1++, $y1++, $x2--, $y2--, $color);
}
}
$rgb = imagecolorat($im, 0, 0);
FloodFill($im, 0, 0);
$color = imagecolorallocate($im, 180, 0, 255);
imagecolortransparent($im, $color);
header("Content-type: image/png");
imagepng($im);
imagedestroy($im);
?>
----
Server IP: 69.147.83.197
Probable Submitter: 79.181.12.22
----
Manual Page -- http://www.php.net/manual/en/function.imagesetpixel.php
Edit -- https://master.php.net/note/edit/108517
Del: integrated -- https://master.php.net/note/delete/108517/integrated
Del: useless -- https://master.php.net/note/delete/108517/useless
Del: bad code -- https://master.php.net/note/delete/108517/bad+code
Del: spam -- https://master.php.net/note/delete/108517/spam
Del: non-english -- https://master.php.net/note/delete/108517/non-english
Del: in docs -- https://master.php.net/note/delete/108517/in+docs
Del: other reasons-- https://master.php.net/note/delete/108517
Reject -- https://master.php.net/note/reject/108517
Search -- https://master.php.net/manage/user-notes.php