設置 | 登錄 | 註冊

目前共有2篇帖子。

原来PHP GD库中的imagefill函数就相当于“画图”中的喷枪工具

1樓 巨大八爪鱼 2015-11-30 22:17
比如代码:
<?php
header('Content-Type: image/png');
$im = imagecreatetruecolor(500, 500);

$white = imagecolorallocate($im, 0xff, 0xff, 0xff); // #FFFFFF
imagefill($im, 0, 0, $white); // 设置背景颜色

$blue = imagecolorallocate($im, 0x00, 0x00, 0xff); // #0000FF
imageline($im, 40, 20, 390, 450, $blue);
imageline($im, 420, 20, 380, 450, $blue);
imageline($im, 28, 35, 460, 28, $blue);

$green = imagecolorallocate($im, 0xb5, 0xe6, 0x1d); // #B5E61D
imagefill($im, 300, 200, $green);
imagesetpixel($im, 300, 200, $blue);

imagepng($im);
imagedestroy($im);
?>
输出的图像为:

2樓 巨大八爪鱼 2015-11-30 22:18
刚开始,图像中什么都没有,所以执行imagefill($im, 0, 0, $white);自然而然就把整个图像涂成了白色。
后来画了三条直线,再执行imagefill($im, 300, 200, $green);在中间点击喷枪,就把三条直线中间形成的三角形涂成了绿色。

內容轉換:

回覆帖子
內容:
用戶名: 您目前是匿名發表。
驗證碼:
看不清?換一張
©2010-2025 Purasbar Ver3.0 [手機版] [桌面版]
除非另有聲明,本站採用知識共享署名-相同方式共享 3.0 Unported許可協議進行許可。