我目前正在开发一个使用 PHP 和 LARAVEL 的项目。
目标是当用户填写完调查表后生成如下图表。
我想根据用户在每个类别(“SOI”、“METHODE”、“TERRITOIRE”、“ENVIRONNMENT”)中的答案生成此图像。
例如: 如果我得到:
我必须将这些数字插入到秤上,然后连接每个数字的每个点。
看看下面的图片即可完全理解我的意思。
我尝试使用干预配套,但结果并不如我预期。
查看下面的代码
$image = Image::canvas(700, 700, '#ffffff');
// Define colors
$black = '#000000';
$labelColor = '#0000ff';
$graduationColor = '#c8c8c8';
// Define the center and radius of the circle
$centerX = 350;
$centerY = 350;
$circleRadius = 200; // Reduce the radius to fit the circle in the cross
// Draw the cross in the middle of the image
$crossLength = $circleRadius * 2;
$crossStartX = $centerX - $crossLength / 2;
$crossEndX = $centerX + $crossLength / 2;
$crossStartY = $centerY;
$crossEndY = $centerY;
$image->line($crossStartX, $crossStartY, $crossEndX, $crossEndY, function ($draw) use ($black) {
$draw->color($black);
});
$image->line($centerX, $centerY - $crossLength / 2, $centerX, $centerY + $crossLength / 2, function ($draw) use ($black) {
$draw->color($black);
});
// Draw the circular shape in the middle of the cross
$circleStartX = $centerX - $circleRadius;
$circleEndX = $centerX + $circleRadius;
$circleStartY = $centerY - $circleRadius;
$circleEndY = $centerY + $circleRadius;
$image->ellipse($centerX, $centerY, $circleRadius * 2, $circleRadius * 2, function ($draw) use ($black) {
$draw->border(1, $black);
});
// Output image
// header('Content-type: image/png');
// return $image->encode('png');
$image->save(storage_path('image.png'));
有没有合适的方法来实现这一点?我应该使用一个特定的包来解决这个问题吗?