# HELP API Output to JPEG Using PHP and GD

**URL:** https://forum.kirupa.com/t/help-api-output-to-jpeg-using-php-and-gd/121226
**Category:** Uncategorized
**Created:** [September 1, 2004, 2:26am UTC](https://forum.kirupa.com/t/help-api-output-to-jpeg-using-php-and-gd/121226 "2004-09-01T02:26:45Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![monstruo\_](https://avatars.discourse-cdn.com/v4/letter/m/e79b87/32.png) [@monstruo\_](https://forum.kirupa.com/u/monstruo_)
#### Post date: [September 1, 2004, 2:26am UTC](https://forum.kirupa.com/t/help-api-output-to-jpeg-using-php-and-gd/121226/1 "2004-09-01T02:26:45Z")

</div>

[size=1]Ok, i got the source from Jerry Jasuta to build a Drawing API, everything works perfectly it draws and saves the images into jpg. I have a little problem, how do i make it load images to the same file, I want to be able to load pictures and draw on them then save them into jpg.[/size]

[size=1]Need help …Please…[/size]

[size=1]Actionscripting in the frame,[/size]

drawing=false;  
data=’’;

createEmptyMovieClip(’\_keyListener’,1);  
Key.addListener(\_keyListener);  
\_keyListener.onKeyDown=function(){  
clear();  
\_root.data=’’;  
};

with(\_root)

onMouseDown=function(){  
drawing=true;  
startX=\_xmouse;  
startY=\_ymouse;  
moveTo(startX,startY);  
};  
onMouseUp=function(){  
drawing=false;  
};  
onMouseMove=function(){  
if(drawing==true){  
lineStyle(2);  
lineTo(\_xmouse,\_ymouse);

if(drawing==true && \_ymouse\<200){  
lineStyle(2);  
lineTo(\_xmouse,_ymouse);  
 root.data+=startX+’’+startY+’_’+_xmouse+’_’+\_ymouse+’-’;  
startX=\_xmouse;  
startY=\_ymouse;  
}  
updateAfterEvent();  
};  
}

[color=red]This makes the PHP Part work,[/color]

$data=$HTTP\_POST\_VARS[“data”];

$image=imagecreatetruecolor(300,200);  
$imagelines=imagecreate(300,200);

$background=imagecolorallocate($imagelines,255,255,255);  
$linecolor=imagecolorallocate($imagelines,0,0,0);

$lines=explode("-",$data);

for($l=0;$l\<count($lines)-1;$l++){

$lineData=explode("\_",$lines[$l]);

imageline($imagelines,$lineData[0],$lineData[1],$lineData[2],$lineData[3],$linecolor);  
}

imagecopyresampled($image,$imagelines,0,0,0,0,300,200,300,200);

imagejpeg($image,“created.jpg”);

imagedestroy($image);  
imagedestroy($imagelines);

print "\<html\>  
\<head\>  
\<title\>\</title\>  
\</head\>  
\<body bgColor=‘cccccc’\>  
\<center\>  
\<p\>  
\<img src=‘created.jpg’\>  
\</center\>  
\</body\>  
\</html\>
