<?
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header("Cache-Control: no-cache, must-revalidate");
// Convert SWF Drawing API data to
// JPEG, PNG, and static SWF
// Example by Jerry Jasuta
// requires GD and Ming libraries
// grab the drawing data
$data=$HTTP_POST_VARS["data"];
// create truecolor image for jpeg output
// and pallette image for drawing creation
$background=imagecreatetruecolor(300,200);
$image=imagecreate(300,200);
imageantialias($image,true);
imageantialias($background,true);
$backgroundColor=imagecolorallocate($image,255,255,255);
$colors=Array();
// create movie for swf output
// and set it's attributes
$movie=new SWFMovie();
$movie->setDimension(300,200);
$movie->setBackground(255,255,255);
// split up the drawing data into lines
$shapes=explode("-",$data);
// loop through the shapes
for($s=0;$s<count($shapes)-1;$s++){
// create the new swfshape
$l=new SWFShape();
// split up the shape data
$shapeData=explode("_",$shapes[$s]);
// check/set color allocations and line thickness
imagesetthickness($image,$shapeData[5]);
$shapeData[6]=substr($shapeData[6],2);
$r=hexdec(substr($shapeData[6],0,2));
$g=hexdec(substr($shapeData[6],2,2));
$b=hexdec(substr($shapeData[6],4,2));
// check if color is already allocated
$shapecolor=imagecolorexact($image,$r,$g,$b);
if($shapecolor==(-1)){
$shapecolor=imagecolorallocate($image,$r,$g,$b);
}
$l->setLine($shapeData[5],$r,$g,$b);
// set the swffill
if($shapeData[7]=="true"){
$l->setRightFill($r,$g,$b);
}else{
$l->setRightFill(0);
}
// draw the line shapes
if($shapeData[0]=="line"){
imageline($image,$shapeData[1],$shapeData[2],$shapeData[3],$shapeData[4],$shapecolor);
$l->movePenTo($shapeData[1],$shapeData[2]);
$l->drawLineTo($shapeData[3],$shapeData[4]);
}
// draw the rectangle shapes
if($shapeData[0]=="rectangle"){
if($shapeData[7]=="true"){
imagefilledrectangle($image,$shapeData[1],$shapeData[2],$shapeData[3],$shapeData[4],$shapecolor);
}else{
imagerectangle($image,$shapeData[1],$shapeData[2],$shapeData[3],$shapeData[4],$shapecolor);
}
$l->movePenTo($shapeData[1],$shapeData[2]);
$l->drawLineTo($shapeData[3],$shapeData[2]);
$l->drawLineTo($shapeData[3],$shapeData[4]);
$l->drawLineTo($shapeData[1],$shapeData[4]);
$l->drawLineTo($shapeData[1],$shapeData[2]);
}
// draw the curve shapes
if($shapeData[0]=="curve"){
$difX=$shapeData[1]-$shapeData[3];
$difY=$shapeData[2]-$shapeData[4];
if($difX<0 && $difY<0){$startD=270;$endD=360;}
if($difX>0 && $difY<0){$startD=180;$endD=270;}
if($difX>0 && $difY>0){$startD=90;$endD=180;}
if($difX<0 && $difY>0){$startD=0;$endD=90;}
imagesetthickness($image,$shapeData[5]);
imagearc($image,$shapeData[1],$shapeData[4],abs($difX)*2,abs($difY)*2,$startD,$endD,$shapecolor);
$l->movePenTo($shapeData[1],$shapeData[2]);
$l->drawCurveTo($shapeData[3],$shapeData[2],$shapeData[3],$shapeData[4]);
}
// draw the circle shapes
if($shapeData[0]=="circle"){
$w=abs($shapeData[1]-$shapeData[3]);
if($w==0){$w=0.1;}
$h=abs($shapeData[2]-$shapeData[4]);
if($h==0){$h=0.1;}
imagesetthickness($image,$shapeData[5]);
if($shapeData[7]=="true"){
imagefilledarc($image,$shapeData[1],$shapeData[2],$w*2,$h*2,0,359,$shapecolor,IMAGE_ARC_PIE);
imagefilledarc($image,$shapeData[1],$shapeData[2],$w*2,$h*2,359,360,$shapecolor,IMAGE_ARC_PIE);
}else{
imagearc($image,$shapeData[1],$shapeData[2],$w*2,$h*2,0,359,$shapecolor);
imagearc($image,$shapeData[1],$shapeData[2],$w*2,$h*2,359,360,$shapecolor);
}
$j=$w*0.70711;
$n=$h*0.70711;
$i=$j-($h-$n)*$w/$h;
$M=$n-($w-$j)*$h/$w;
$l->movePenTo($shapeData[1]+$w,$shapeData[2]);
$l->drawCurveTo($shapeData[1]+$w,$shapeData[2]-$M,$shapeData[1]+$j,$shapeData[2]-$n);
$l->drawCurveTo($shapeData[1]+$i,$shapeData[2]-$h,$shapeData[1],$shapeData[2]-$h);
$l->drawCurveTo($shapeData[1]-$i,$shapeData[2]-$h,$shapeData[1]-$j,$shapeData[2]-$n);
$l->drawCurveTo($shapeData[1]-$w,$shapeData[2]-$M,$shapeData[1]-$w,$shapeData[2]);
$l->drawCurveTo($shapeData[1]-$w,$shapeData[2]+$M,$shapeData[1]-$j,$shapeData[2]+$n);
$l->drawCurveTo($shapeData[1]-$i,$shapeData[2]+$h,$shapeData[1],$shapeData[2]+$h);
$l->drawCurveTo($shapeData[1]+$i,$shapeData[2]+$h,$shapeData[1]+$j,$shapeData[2]+$n);
$l->drawCurveTo($shapeData[1]+$w,$shapeData[2]+$M,$shapeData[1]+$w,$shapeData[2]);
}
// add the swfshape to the stage
$movie->add($l);
} // end drawing data loop
// copy the pallette drawing image to the truecolor jpeg image
imageantialias($image,true);
imageantialias($background,true);
imagecopyresampled($background,$image,0,0,0,0,300,200,300,200);
// save the jpeg to file
$uniqueFile=rand();
imagejpeg($background,"jpg/$uniqueFile.jpg");
// save the png to file
imagepng($background,"png/$uniqueFile.png");
// save the movie to file
$movie->save("swf/$uniqueFile.swf");
// free up the image allocations
imagedestroy($background);
imagedestroy($image);
// check file sizes
$jpg=filesize("jpg/$uniqueFile.jpg");
$png=filesize("png/$uniqueFile.png");
$swf=filesize("swf/$uniqueFile.swf");
// print out the hmtl page
print "<html>
<head>
<title>MX Drawing API Converted To JPEG/PNG/SWF Using PHP and GD</title>
</head>
<body bgColor='cccccc'>
<center>
MX Drawing API Converted To JPEG/PNG/SWF Using PHP and GD<p>
<b>JPEG</b><br><img src='jpg/$uniqueFile.jpg'><br>
file size = $jpg<br>
note-if images don't load right away<br>
<a href='jpg/$uniqueFile.jpg' target='_blank'>Click here for jpeg file</a><p>
<b>PNG</b><br><img src='png/$uniqueFile.png'><br>
file size = $png<br>
note-if images don't load right away<br>
<a href='png/$uniqueFile.png' target='_blank'>Click here for png file</a><p>
<b>Static SWF</b><br><OBJECT BORDER=0 classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" codebase=\"http://active.macromedia.com/flash2/cabs/swflash.cab#version=5,0,0,0\" ID=objects WIDTH=\"300\" HEIGHT=\"250\">
<PARAM NAME=movie VALUE=\"swf/$uniqueFile.swf\">
<EMBED src=\"swf/$uniqueFile.swf\" WIDTH=\"300\" HEIGHT=\"250\" TYPE=\"application/x-shockwave-flash\" PLUGINSPAGE=\"http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash\">
</OBJECT><br>
file size = $swf<br>
note-if images don't load right away<br>
<a href='swf/$uniqueFile.swf' target='_blank'>click here for swf file</a><p>
<img src=\"counter.php\" width=1 height=1><br>
<i>Note - Images are deleted daily</i>
</center>
</body>
</html>
";
$today=@date("Y-m-d");
if($handle=@opendir("jpg")){
while(false!==($file=@readdir($handle))){
if($file!=="." && $file!==".."){
if(!@is_dir("$file")){
$filedate=@date("Y-m-d", @filemtime("jpg/".$file));
if($today > $filedate){
@unlink("jpg/".$file);
}
}
}
}
@closeDir($handle);
}
if($handle=@opendir("png")){
while(false!==($file=@readdir($handle))){
if($file!=="." && $file!==".."){
if(!@is_dir("$file")){
$filedate=@date("Y-m-d", @filemtime("png/".$file));
if($today > $filedate){
@unlink("png/".$file);
}
}
}
}
@closeDir($handle);
}
if($handle=@opendir("swf")){
while(false!==($file=@readdir($handle))){
if($file!=="." && $file!==".."){
if(!@is_dir("$file")){
$filedate=@date("Y-m-d", @filemtime("swf/".$file));
if($today > $filedate){
@unlink("swf/".$file);
}
}
}
}
@closeDir($handle);
}
?>
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