如何在PHP中使用imagesetstyle()函数设置线条绘制样式?
imagesetstyle() 是PHP中的一个内置函数,用于设置线条绘制的样式。它可以被所有线条绘制函数使用,例如 imagepolygon 或 imageline。
语法
bool imagesetstyle(resource $image, array $style)
参数
imagesetstyle() 接受两个参数:$image 和 $style。
$image − 指定要操作的图像资源。
$style − 指定像素颜色的数组。
返回值
imagesetstyle() 成功时返回True,失败时返回False。
示例1
<?php
header("Content-type: image/jpeg");
$img = imagecreatetruecolor(700, 300);
$w = imagecolorallocate($img, 122, 122, 122);
$red = imagecolorallocate($img, 255, 0, 0);
/* Draw a dashed line, 5 red pixels, 5 white pixels */
$style = array($red, $red, $red, $red, $red, $w, $w, $w, $w, $w);
imagesetstyle($img, $style);
imageline($img, 0, 0, 200, 200, IMG_COLOR_STYLED);
/* Draw a line of happy faces using imagesetbrush() with imagesetstyle */
$style = array($w, $w, $w, $w, $w, $w, $w, $w, $w, $w, $w, $w, $red);
imagesetstyle($img, $style);
$brush = imagecreatefrompng('C:\xampp\htdocs\Images\img34.png');
$w2 = imagecolorallocate($brush, 255, 255, 255);
imagecolortransparent($brush, $w2);
imagesetbrush($img, $brush);
imageline($img, 200, 0, 0, 200, IMG_COLOR_STYLEDBRUSHED);
imagejpeg($img);
imagedestroy($img);
?>输入图像

输出图像
.jpg)
示例2
<?php // Load the png image using imagecreatefrompng() function. $img = imagecreatefrompng('C:\xampp\htdocs\Images\img34.png'); // Allocated the blue and green colors $blue = imagecolorallocate($img, 0, 0, 255); $green = imagecolorallocate($img, 0, 255, 0); // Draw a dashed line, 5 blue pixels, 5 white pixels $style = array($blue, $blue, $blue, $blue, $blue, $green, $green, $green, $green, $green); imagesetstyle($img, $style); imageline($img, 0, 100, 800, 100, IMG_COLOR_STYLED); // Output image to the browser header('Content-type: image/png'); imagepng($img); ?>
输出
.jpg)
广告
数据结构
网络
关系数据库管理系统 (RDBMS)
操作系统
Java
iOS
HTML
CSS
Android
Python
C语言编程
C++
C#
MongoDB
MySQL
Javascript
PHP