設定畫線的風格

imagesetstyle

(PHP 4 >= 4.0.6, PHP 5, PHP 7, PHP 8)

imagesetstyle — 設定畫線的風格

說明

imagesetstyle(resource $image, array $style): bool

imagesetstyle() 設定所有畫線的函式(例如 imageline() 和 imagepolygon())在使用特殊顏色 IMG_COLOR_STYLED 或者用 IMG_COLOR_STYLEDBRUSHED 畫一行影象時所使用的風格。

參數

image

由圖像建立函式(例如imagecreatetruecolor())返回的 GdImage 對象。

style

畫素組成的陣列。你可以通過常量 IMG_COLOR_TRANSPARENT 來新增一個透明畫素。

返回值

成功時返回 true, 或者在失敗時返回 false。

範例

下面的示例指令碼在畫布上從左上角到右下角畫一行虛線:

示例 #1 imagesetstyle() 例子

<?php
header
("Content-type: image/jpeg");
$im  = imagecreatetruecolor(100, 100);
$w   = imagecolorallocate($im, 255, 255, 255);
$red = imagecolorallocate($im, 255, 0, 0);

/* 畫一條虛線,5 個紅色畫素,5 個白色畫素 */
$style = array($red, $red, $red, $red, $red, $w, $w, $w, $w, $w);
imagesetstyle($im, $style);
imageline($im, 0, 0, 100, 100, IMG_COLOR_STYLED);

/* 用 imagesetbrush() 和 imagesetstyle 畫一行笑臉 */
$style = array($w, $w, $w, $w, $w, $w, $w, $w, $w, $w, $w, $w, $red);
imagesetstyle($im, $style);

$brush = imagecreatefrompng("http://www.libpng.org/pub/png/images/smile.happy.png");
$w2 = imagecolorallocate($brush, 255, 255, 255);
imagecolortransparent($brush, $w2);
imagesetbrush($im, $brush);
imageline($im, 100, 0, 0, 100, IMG_COLOR_STYLEDBRUSHED);

imagejpeg($im);
imagedestroy($im);
?>

以上例程的輸出類似於:

Output of example : imagesetstyle()

參見

Leave a Reply

Your email address will not be published. Required fields are marked *