我刚刚编写了此代码以生成图像
<?php
$canvas = imagecreatetruecolor(800, 350);
$pink = imagecolorallocate($canvas, 255, 105, 180);
$white = imagecolorallocate($canvas, 255, 255, 255);
$green = imagecolorallocate($canvas, 132, 135, 28);
imagefill($canvas, 0, 0, $white); // BACKGROUND
function drawlinebox($x1, $y1, $x2, $y2, $height, $color){
global $canvas;
imagesetthickness ( $canvas, 1 );
for ($i=1; $i < $height; $i++){
imageline( $canvas, $x1, $y1, $x2, $y2, $color );
$y1++; $y2++;
}
}
drawlinebox(20, 20, 780, 300, 30, $green);
drawlinebox(20, 300, 780, 20, 30, $pink);
// Output and free from memory
header('Content-Type: image/png');
imagepng($canvas, NULL, 9);
imagedestroy($canvas);
?>
但是我也希望该图像自动保存在服务器上。认为这是一项日常工作。它创建图像,然后将图像保存在服务器上以备后用,并将保存的图像位置插入数据库中。
如手册中所述,imagepng()
的第二个参数是imagepng()
,它允许您将结果存储在文件中。
您有任何解决办法吗?我当时正在考虑这样做。但不知道如何在不本地保存文件的情况下直接将其上传到数据库。