PHP Developers Network

A community of PHP developers offering assistance, advice, discussion, and friendship.
 
Loading
It is currently Wed Nov 26, 2014 12:19 pm

All times are UTC - 5 hours




Post new topic Reply to topic  [ 2 posts ] 
Author Message
PostPosted: Fri May 30, 2008 8:43 am 
Offline
Forum Newbie

Joined: Fri May 30, 2008 8:38 am
Posts: 1
Hello all, I'm new here.
I'm developing a Flash app in which the user traces his or her face. Done. The coordinates are being sent to a PHP page which fills a polygon. Done. Now what I would like to do is instead of filling the polygon, convert it to alpha. Can this be done? I'm attaching my code and a screenshot of what I've done so far.
Any help is appreciated.
Syntax: [ Download ] [ Hide ]
<?
    /* INITIALIZE A VARIABLE */
        $coordinates=substr($_GET['c'],0,strlen($_GET['c'])-1);
    /* BUILD AN ARRAY */
        $temp=split(',',$coordinates);
    /* CREATE THE IMAGE */
        $image=imagecreatetruecolor(400, 370);
    /* USE A FILL */
        $fill_color=imagecolorallocate($image, 255, 255, 255);
    /* DRAW IT */
        imagefilledpolygon($image, $temp, (count($temp)/2), $fill_color);
    /* SET THE HEADER */
        header('Content-type: image/png');
    /* FLUSH THE IMAGE */
        imagepng($image);
        imagedestroy($image);
?>


Attachments:
screenshots.gif
screenshots.gif [ 56.23 KiB | Viewed 929 times ]
Top
 Profile  
 
PostPosted: Sat Jun 14, 2008 10:54 am 
Offline
Jedi Mod
User avatar

Joined: Tue Dec 21, 2004 6:03 pm
Posts: 5263
Location: usrlab.com
A nice prompt reply.. ;)

You need to set the image to retain the alpha channel, but also replace any alpha values rather than merging them. You also need to set the alpha value of the fill pixels to 127 (transparent)...

Syntax: [ Download ] [ Hide ]
<?php
 
    /* INITIALIZE A VARIABLE */
    $coordinates="20,60,
                  120,60,
                  160,120,
                  120,200"
;
    /* BUILD AN ARRAY */
        $temp=split(',',$coordinates);
    /* CREATE THE IMAGE */
        $image=imagecreatetruecolor(400, 370);
        imagesavealpha($image, true); //Save the alpha values
        imagealphablending($image, false); //Replace the alpha value for any filled pixel rather than adding them
    /* USE A FILL */
        $fill_color=imagecolorallocatealpha($image, 255, 255, 255, 127); //Allocate a color with an alpha channel value
    /* DRAW IT */
        imagefilledpolygon($image, $temp, (count($temp)/2), $fill_color);
    /* SET THE HEADER */
        header('Content-type: image/png');
    /* FLUSH THE IMAGE */
        imagepng($image);
        imagedestroy($image);
 


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC - 5 hours


Who is online

Users browsing this forum: No registered users and 0 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
Powered by phpBB® Forum Software © phpBB Group