2012-06-19 24 views
0

可能你可以帮助我。 我需要一个函数来绘制_GET或_POST字符串的折线路径,并将生成的图像保存到文件夹中。 例如,我的链接将如下所示:http://img.domain.com/?points = 1,5,-70,300,250,500 ... 如果图像已生成并且未更改 - >从文件夹加载它。否则生成一个新的。php gd函数从数组中绘制折线

我的代码在这里:

if (isset($_POST['points'])) { 

    $points = $_POST['points']; 


    $image = imagecreate(200, 200); 

    $white = imagecolorallocate($image, 255, 255, 255); 
    $black = imagecolorallocate($image, 0, 0, 0); 

    ... polyline path drawing here...? 
    imageline($image, 10, 10, 10, 190, $black); 

    header('Content-Type: image/png'); 
    imagepng($image); 
    imagedestroy($image); 

    ... how to save it to the server? 

} 

感谢。

回答

1

为了节省您可以使用imagepng第二个(可选)参数图片:

imagepng($image, 'saved.png'); 

因为你将调用imageline一个循环中折线 - 究竟如何取决于你$points值的结构。

0

要将图像保存到服务器上,请使用图像函数的第二个参数来指定位置和文件名。

//specify the path on the server where you want to save the image 
$path_image = 'saved-example.png'; 
imagepng($image, $path_image); 

imagepng($image); 
imagedestroy($image); 

图像将被保存到该路径。