extension=gd
라인을 찾을 수없는 경우 웹 서버를 수동으로 추가하여 다시 시작하십시오.
<!DOCTYPE html>
<html>
<head>
<title>페인트 보드</title>
<style>
#canvas {
border: 1px solid #000;
}
</style>
</head>
<body>
<form method="post" action="create_canvas.php">
<label for="width">너비:</label>
<input type="number" id="width" name="width" min="100" max="1000" required><br>
<label for="height">높은:</label>
<input type="number" id="height" name="height" min="100" max="1000" required><br>
<input type="submit" value="创建페인트 보드">
</form>
</body>
</html>
이 양식은 post request를 create_canvas.php 에 보내고 사용자의 너비 및 높이 입력을 제출합니다.
<?php
// 获取너비和높은参数
$width = $_POST['width'];
$height = $_POST['height'];
// 빈 캔버스를 만듭니다
$canvas = imagecreatetruecolor($width, $height);
?>
<?php
// 캔버스 렌더링
for ($x = 0; $x < $width; $x++) {
for ($y = 0; $y < $height; $y++) {
$color = imagecolorallocate($canvas, mt_rand(0, 255), mt_rand(0, 255), mt_rand(0, 255));
imagesetpixel($canvas, $x, $y, $color);
}
}
// 브라우저에 이미지를 출력합니다
header('Content-Type: image/png');
imagepng($canvas);
imagedestroy($canvas);
?>
이 코드는 imagepng 함수를 통해 무작위로 생성 된 RGB 색상과 출력 PNG 형식 이미지로 캔버스를 채 웁니다.