<?
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"];
$imagetype=$HTTP_POST_VARS["imagetype"];

// create truecolor image for jpeg output
// and pallette image for drawing creation
if($imagetype=="jpg" || $imagetype=="png"){
$background=imagecreatetruecolor(600,300);
$image=imagecreate(600,300);
imageantialias($image,true);
imageantialias($background,true);
$backgroundColor=imagecolorallocate($image,255,255,255);
$colors=Array();
}

// create movie for swf output
// and set it's attributes
if($imagetype=="swf"){
$movie=new SWFMovie();
$movie->setDimension(600,300);
$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
  
if($imagetype=="swf"){$l=new SWFShape();}

  
// split up the shape data
  
$shapeData=explode("_",$shapes[$s]);

  
// check/set color allocations and line thickness
  
if($imagetype=="jpg" || $imagetype=="png"){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
  
if($imagetype=="jpg" || $imagetype=="png"){$shapecolor=imagecolorexact($image,$r,$g,$b);
  if(
$shapecolor==(-1)){
    
$shapecolor=imagecolorallocate($image,$r,$g,$b);
  }}
  if(
$imagetype=="swf"){$l->setLine($shapeData[5],$r,$g,$b);}

  
// set the swffill
  
if($imagetype=="swf"){if($shapeData[7]=="true"){
    
$l->setRightFill($r,$g,$b);
  }else{
    
$l->setRightFill(0);
  }}

  
// draw the line shapes

  
if($shapeData[0]=="line"){
    if(
$imagetype=="jpg" || $imagetype=="png"){imageline($image,$shapeData[1],$shapeData[2],$shapeData[3],$shapeData[4],$shapecolor);}
    if(
$imagetype=="swf"){$l->movePenTo($shapeData[1],$shapeData[2]);
    
$l->drawLineTo($shapeData[3],$shapeData[4]);
    }
  }

  
// draw the rectangle shapes
  
if($shapeData[0]=="rectangle"){
    if(
$imagetype=="jpg" || $imagetype=="png"){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);
    }}
    if(
$imagetype=="swf"){
    
$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;}
  if(
$imagetype=="jpg" || $imagetype=="png"){imagesetthickness($image,$shapeData[5]);
  
imagearc($image,$shapeData[1],$shapeData[4],abs($difX)*2,abs($difY)*2,$startD,$endD,$shapecolor);
  }
  if(
$imagetype=="swf"){$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;}
  if(
$imagetype=="jpg" || $imagetype=="png"){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;
  
  if(
$imagetype=="swf"){
  
$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
  
if($imagetype=="swf"){$movie->add($l);}

}  
// end drawing data loop

// copy the pallette drawing image to the truecolor jpeg image
if($imagetype=="jpg" || $imagetype=="png"){
imageantialias($image,true);
imageantialias($background,true);
imagecopyresampled($background,$image,0,0,0,0,600,300,600,300);
}

// save the jpeg to file
$uniqueFile=rand();
if(
$imagetype=="jpg"){imagejpeg($background,"jpg/$uniqueFile.jpg");}

// save the png to file
if($imagetype=="png"){imagepng($background,"png/$uniqueFile.png");}

// free up the image allocations
if($imagetype=="jpg" || $imagetype=="png"){
imagedestroy($background);
imagedestroy($image);
}

// save the movie to file
if($imagetype=="swf"){$movie->save("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>
"
;
if(
$imagetype=="jpg"){
print
"<b>JPEG</b><br><img src='jpg/$uniqueFile.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>
"
;
}

if(
$imagetype=="png"){
print
"<b>PNG</b><br><img src='png/$uniqueFile.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>
"
;
}

if(
$imagetype=="swf"){
print
"<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=\"600\" HEIGHT=\"300\">
<PARAM NAME=movie VALUE=\"swf/$uniqueFile.swf\">
<EMBED src=\"swf/$uniqueFile.swf\" WIDTH=\"600\" HEIGHT=\"300\" TYPE=\"application/x-shockwave-flash\" PLUGINSPAGE=\"http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash\">
</OBJECT><br>
note-if images don't load right away<br>
<a href='swf/$uniqueFile.swf' target='_blank'>click here for swf file</a><p>
"
;
}

print
"<img src=\"counter.php\" width=1 height=1>
</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