note 103132 added to function.imagecolorat
| From: | chandrachur at elegantsystems dot net | Date: | Mon, 28 Mar 2011 09:53:56 +0000 |
| Subject: | note 103132 added to function.imagecolorat | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-178259@lists.php.net to get a copy of this message | ||
Here is a fun code for making images with white bg transparent. Well it can work with any bg but you
need to adjust the color values accordingly. Works best with plain dual colors. I searched for this
kind of code a lot but unable to find one ...see if this helps someone.
<?php
function transparentImage($src){ //making images with white bg transparent
$r1=80;
$g1=80;
$b1=80;
for($x = 0; $x < imagesx($src); ++$x)
{
for($y = 0; $y < imagesy($src); ++$y)
{
$color=imagecolorat($src, $x, $y);
$r = ($color >> 16) & 0xFF;
$g = ($color >> 8) & 0xFF;
$b = $color & 0xFF;
for($i=0;$i<270;$i++){
if($r.$g.$b==($r1+$i).($g1+$i).($b1+$i)){
$trans_colour = imagecolorallocatealpha($src, 0, 0, 0, 127);
imagefill($src, $x, $y, $trans_colour);
}
}
}
}
return $src;
}
$image='abc/abc.jpg';
$src = imagecreatefromjpeg($image);
$src=transparentImage($src); //Lets make the jpegs transparent
?>
----
Server IP: 69.147.83.197
Probable Submitter: 115.110.253.141
----
Manual Page -- http://www.php.net/manual/en/function.imagecolorat.php
Edit -- https://master.php.net/note/edit/103132
Del: integrated -- https://master.php.net/note/delete/103132/integrated
Del: useless -- https://master.php.net/note/delete/103132/useless
Del: bad code -- https://master.php.net/note/delete/103132/bad+code
Del: spam -- https://master.php.net/note/delete/103132/spam
Del: non-english -- https://master.php.net/note/delete/103132/non-english
Del: in docs -- https://master.php.net/note/delete/103132/in+docs
Del: other reasons-- https://master.php.net/note/delete/103132
Reject -- https://master.php.net/note/reject/103132
Search -- https://master.php.net/manage/user-notes.php