Reputation: 3402
may be you can help me. I need a function to draw polyline path from _GET or _POST string and save generated image to the folder. For example my link will looks like: http://img.domain.com/?points = 1,5,-70,300,250,500... If image already generated and do not changed -> load it from folder. Else generate new one.
My code here:
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?
}
Thanks.
Upvotes: 0
Views: 957
Reputation: 1
To save an image to the server on the fly, use the image function's second parameter to specify a location and filename.
//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);
Image will be saved to that path.
Upvotes: 0
Reputation: 437554
To save the image you can use the second (optional) parameter of imagepng
:
imagepng($image, 'saved.png');
For the polyline you will be calling imageline
inside a loop -- exactly how depends on what your $points
value is structured.
Upvotes: 1