<?
// Use Flash MX drawing API and PHP's GD and Ming modules
// to create images and convert them to
// PNG, JPEG, and static SWF formats
// Jerry Jasuta
// create the swf movie
ming_useswfversion(6);
$movie = new SWFMovie();
$movie->setDimension(300,250);
$movie->setBackground(255,255,255);
$movie->setRate(31);
// create a textfield to hold drawing data
$t=new SWFTextField();
$t->setFont(new SWFFont("Arial.fdb"));
$t->setName("data");
$movie->add($t);
// create the canvas image
// canvas
$s=new SWFShape();
$s->setLine(2,0,0,0,255);
$s->movePenTo(1,1);
$s->drawLine(298,0);
$s->drawLine(0,198);
$s->drawLine(-298,0);
$s->drawLine(0,-198);
$i=$movie->add($s);
$i->moveTo(0,0);
// mx actionscript
$strAction = "
// variables
drawing=false;
// create a key listener for clearing the canvas
createEmptyMovieClip('_keyListener',1);
Key.addListener(_keyListener);
_keyListener.onKeyDown=function(){
clear();
_root.data='';
};
// root event handlers
with(_root){
onMouseDown=function(){
drawing=true;
startX=_xmouse;
startY=_ymouse;
moveTo(startX,startY);
};
onMouseUp=function(){
drawing=false;
};
onMouseMove=function(){
difX=startX-_xmouse;if(difX<0){difX*=(-1);}
difY=startY-_ymouse;if(difY<0){difY*=(-1);}
length=Math.sqrt(difY*difY+difX*difX);
// add the current drawing data to the data variable
if(drawing==true && length>5 && _ymouse<200){
lineStyle(1);
lineTo(_xmouse,_ymouse);
_root.data+=startX+'_'+startY+'_'+_xmouse+'_'+_ymouse+'-';
startX=_xmouse;
startY=_ymouse;
}
updateAfterEvent();
};
}
// end of actionscript block
";
// create the buttons using getURL
// to post the data to the conversion scripts
$t=new SWFText();
$t->setFont(new SWFFont("Arial.fdb"));
$t->setHeight(20);
$t->setColor(0,0,255);
$textWidth=$t->getWidth("Convert Drawing To:");
$t->addString("Convert Drawing To:");
$i=$movie->add($t);
$i->moveTo(150-($textWidth/2),215);
$t=new SWFText();
$t->setFont(new SWFFont("Arial.fdb"));
$t->setHeight(20);
$t->setColor(255,255,255);
$textWidth=$t->getWidth("JPEG");
$t->addString("JPEG");
$s=new SWFShape();
$s->setRightFill(0,0,255);
$s->drawLine($textWidth+10,0);
$s->drawLine(0,40);
$s->drawLine(-($textWidth+10),0);
$s->drawLine(0,-40);
$b=new SWFButton();
$b->addShape($s, SWFBUTTON_UP | SWFBUTTON_OVER | SWFBUTTON_DOWN | SWFBUTTON_HIT);
$b->setAction(new SWFAction("getURL('create-jpeg.php','_blank','POST');"));
$i=$movie->add($b);
$i->moveTo(50-($textWidth/2),220);
$i=$movie->add($t);
$i->moveTo(50-($textWidth/2)+5,242);
$t=new SWFText();
$t->setFont(new SWFFont("Arial.fdb"));
$t->setHeight(20);
$t->setColor(255,255,255);
$textWidth=$t->getWidth("JPEG");
$t->addString("PNG");
$b=new SWFButton();
$b->addShape($s, SWFBUTTON_UP | SWFBUTTON_OVER | SWFBUTTON_DOWN | SWFBUTTON_HIT);
$b->setAction(new SWFAction("getURL('create-png.php','_blank','POST');"));
$i=$movie->add($b);
$i->moveTo(125-($textWidth/2),220);
$i=$movie->add($t);
$i->moveTo(125-($t->getWidth("PNG")/2)+5,242);
$t=new SWFText();
$t->setFont(new SWFFont("Arial.fdb"));
$t->setHeight(20);
$t->setColor(255,255,255);
$textWidth=$t->getWidth("Static SWF");
$t->addString("Static SWF");
$s=new SWFShape();
$s->setRightFill(0,0,255);
$s->drawLine($textWidth+10,0);
$s->drawLine(0,40);
$s->drawLine(-($textWidth+10),0);
$s->drawLine(0,-40);
$b=new SWFButton();
$b->addShape($s, SWFBUTTON_UP | SWFBUTTON_OVER | SWFBUTTON_DOWN | SWFBUTTON_HIT);
$b->setAction(new SWFAction("getURL('create-swf.php','_blank','POST');"));
$i=$movie->add($b);
$i->moveTo(225-($textWidth/2),220);
$i=$movie->add($t);
$i->moveTo(225-($textWidth/2)+5,242);
// add the actions to the movie
$movie->add(new SWFAction(str_replace("\r", "", $strAction)));
// save and output the movie
$movie->save("draw-jpeg.swf");
$revitalizer=rand();
print "<html><body><center><OBJECT BORDER=1 classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" codebase=\"http://active.macromedia.com/flash2/cabs/swflash.cab#version=4,0,0,0\" ID=objects WIDTH=\"300\" HEIGHT=\"250\">
<PARAM NAME=movie VALUE=\"draw-jpeg.swf?$revitalizer\">
<EMBED src=\"draw-jpeg.swf?$revitalizer\" WIDTH=\"300\" HEIGHT=\"250\" TYPE=\"application/x-shockwave-flash\" PLUGINSPAGE=\"http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash\">
</OBJECT></center></body></html>
";
?>
Free Hosting Provide By: Web Hosting Service http://www.hostrocket.com
Make $50 Per Sale: VoIP Affiliate Program http://affiliates.viatalk.com
ViaTalk: Internet Phone Service http://www.viatalk.com