views:

78

answers:

1

Hello world. I am trying to create the silhouette of PNG image with transparencies. Here is my code


//file that i am working with
$file='http://www.google.com/mapfiles/turkey.png';
$im  =imagecreatefrompng($file);
imagealphablending($im, false);
imagesavealpha($im, true);
$imw      =imagesx($im);
$imh      =imagesy($im);
//turkey body color
$bodycolor=imagecolorallocatealpha($im, 144, 144, 144, 50);
//imageholder
$imnew    =imagecreatetruecolor($imh, $imh);
imagealphablending($imnew, false);
imagesavealpha($imnew, true);
$transparent_color=imagecolorallocatealpha($imnew, 0, 0, 0, 127);
imagecolortransparent($imnew, $transparent_color);
imagefilledrectangle($imnew, 0, 0, $imh, $imh, $transparent_color);
for ($i=0; $i > 24;
        //all not transparent pixels are copied to imageholder
        if ($alpha != 127)
            {
            imagesetpixel($imnew, $i, $j, $bodycolor);
            }
        }
    }
//blur filter
imagefilter($imnew, IMG_FILTER_GAUSSIAN_BLUR);
imagefilter($imnew, IMG_FILTER_GAUSSIAN_BLUR);
imagefilter($imnew, IMG_FILTER_GAUSSIAN_BLUR);
header ("Content-type: image/png");
imagepng ($imnew);
imagedestroy ($imnew);
?>

So, I need to get the silhouette ot the turkey with blurred edges. What I get now looks like link text. I need edges to be blurred "outside", so the farther the pixel was from edge, the more transparent it was with the same rbg. And imagefilter also lifts the turkey a bit :) Please help, I am trying to solve this for days.

A: 

For more complex image manipulations like these, I would highly recommend you use ImageMagick: http://www.imagemagick.org

It's pretty easy to install unto your server, very fast and has great documentation. They have a whole section for what you're talking about: http://www.imagemagick.org/Usage/channels/

Fox
Unfortunately I can't use Imagick on my server. But thanks for reply :)
Tim