Re: Images in PHP
| From: | Rasmus Lerdorf | Date: | Fri, 05 Jan 2001 02:31:55 +0000 |
| Subject: | Re: Images in PHP | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-32801@lists.php.net to get a copy of this message | ||
> Has anyone or any group made a library for image creation that adds drop
> shadows or any cool effect?
I wrote a little command-line shadow tool in PHP that puts a drop shadow
on an image thumbnail. I'll let the code speak for itself. It's a pretty
weird way to approach it, I know. But it only took me about 20 minutes to
write and it solved the immediate problem.
#!/usr/local/bin/php -q
<?
$arr = array("000000",
"000011",
"001122",
"011334",
"124556",
"145666");
$ary = array("045566",
"034556",
"024556",
"011445",
"000124",
"000001");
$bot = "666541";
$im = imagecreatefromgif("/dev/stdin");
$black = ImageColorAllocate($im, 0,0,0);
$c0 = ImageColorAllocate($im, 255,255,255);
$c1 = ImageColorAllocate($im, 220,220,220);
$c2 = ImageColorAllocate($im, 185,185,185);
$c3 = ImageColorAllocate($im, 150,150,150);
$c4 = ImageColorAllocate($im, 135,135,135);
$c5 = ImageColorAllocate($im, 95,95,95);
$c6 = ImageColorAllocate($im, 45,45,45);
$x=0; $y=0;
$sy = imagesy($im);
$sx = imagesx($im);
/* top left */
while(list(,$v)=each($arr)) {
$x=0;
while($x<strlen($v)) {
ImageSetPixel($im,$x,$y,${"c".$v[$x]});
$x++;
}
$y++;
$last=$v;
}
/* left edge */
$x=0;
while($x<strlen($last)) {
ImageLine($im,$x,$y,$x,$sy-5,${"c".$last[$x]});
$x++;
}
$y=$sy-5;
/* bottom left */
while($y<=$sy) {
$x=0;
while($x<strlen($ary[$y-$sy+5])) {
$l = $ary[$y-$sy+5];
ImageSetPixel($im,$x,$y,${"c".$l[$x]});
$x++;
}
$y++;
}
/* bottom edge */
$y=$sy-6;
while($y<$sy) {
ImageLine($im,$x-1,$y,$sx-5,$y,${"c".$bot[$y-$sy+6]});
$y++;
}
/* bottom right */
$y=$sy-6;
while($y<$sy) {
$x=$sx-6;
while($x-$sx+6 < strlen($ary[$y-$sy+6])) {
$l = $ary[$y-$sy+6];
ImageSetPixel($im,$x,$y,${"c".$l[$sx-$x-1]});
$x++;
}
$y++;
}
ImageGif($im);
ImageDestroy($im);
?>