ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
1、用PHP绘制色素的函数: imagesetpixel($image, $x, $y, $color)。 2、用PHP绘制矩形的函数: imagerectangle($image, $x1, $y1, $x2, $y2, $color)。 下面是做的几个测试案例: 在真彩色面板中随机绘制多个颜色不同的色素: $img = imagecreatetruecolor(100, 40); $red = imagecolorallocate($img, 255, 0, 0); imagefill($img, 0, 0, $red); $w = imagesx($img); $h = imagesy($img); for($i=0;$i<300;$i++){ $color = imagecolorallocate($img, mt_rand(0,255), mt_rand(0,255), mt_rand(0,255)); $pix = imagesetpixel($img, mt_rand(0,$w), mt_rand(0,$h), $color); imageline($img, mt_rand(0,$w), mt_rand(0,$h), mt_rand(0,$w), mt_rand(0,$h), $color); } header('Content-type:image/jpeg'); imagejpeg($img); 通过色素在真彩色面板中绘制一条直线: $img = imagecreatetruecolor(300, 300); $color = imagecolorallocate($img, 255, 255, 255); imagefill($img, 0, 0, $color); $red = imagecolorallocate($img, 255, 0, 0); for($i=0;$i<299;$i++){ $pix = imagesetpixel($img, 200, $i, $red); } header('Content-type:image/jpeg'); imagejpeg($img); 在真彩色面板中随机绘制颜色不同的矩形: /*真彩色面板*/ $img = imagecreatetruecolor(400, 400); $red = imagecolorallocate($img, 255, 0, 0); imagefill($img, 0, 0, $red); $w = imagesx($img); $h = imagesy($img); for($i=0;$i<300;$i++){ $color = imagecolorallocate($img, mt_rand(0,255), mt_rand(0,255), mt_rand(0,255)); $rect = imagerectangle($img, mt_rand(0,$w), mt_rand(0,$h), mt_rand(0,$w), mt_rand(0,$h), $color); imagesetthickness($img, 20); } header('Content-type:image/jpeg'); imagejpeg($img); /*图像面板*/ $fileName = 'test.jpg'; $img = imagecreatefromjpeg($fileName); $w = imagesx($img); $h = imagesy($img); for($i=0;$i<300;$i++){ $color = imagecolorallocate($img, mt_rand(0,255), mt_rand(0,255), mt_rand(0,255)); $rect = imagerectangle($img, mt_rand(0,$w), mt_rand(0,$h), mt_rand(0,$w), mt_rand(0,$h), $color); imagesetthickness($img, 1); } header('Content-type:image/jpeg'); imagejpeg($img);