imagesetstyle()函數是PHP中的內置函數,用於設置樣式,以供所有線描函數(如imageline()或imagepolygon())使用。
用法:
bool imagesetstyle( resource $image, array $style )
參數:該函數接受上述和以下描述的兩個參數:
- $image:它指定要處理的圖像資源。
- $style:它指定像素顏色的數組。
返回值:如果成功,則此函數返回TRUE;如果失敗,則返回FALSE。
下麵給出的程序說明了PHP中的imagesetstyle()函數:程序1(在圖像上繪製):
<?php 
// Load the png image 
$image = imagecreatefrompng( 
    'https://media.geeksforgeeks.org/wp-content/uploads/geeksforgeeks-13.png'); 
  
// Prepare the colors 
$red = imagecolorallocate($image, 255, 0, 0); 
$green   = imagecolorallocate($image, 0, 255, 0); 
  
// Draw a dashed line, 5 red pixels, 5 white pixels 
$style = array($red, $red, $red, $red, $red, $green, $green, $green, $green, $green); 
imagesetstyle($image, $style); 
imageline($image, 0, 100, 800, 100, IMG_COLOR_STYLED); 
  
// Output image to the browser 
header('Content-type:image/png'); 
imagepng($image); 
?>輸出:

程序2(在空白圖形上繪圖):
<?php 
//Create a blank image 
$image = imagecreatetruecolor(700, 200); 
  
// Set the background color of image 
$background_color = imagecolorallocate($image, 255, 255, 255); 
  
// Fill background with above selected color 
imagefill($image, 0, 0, $background_color); 
  
// Prepare the colors 
$red = imagecolorallocate($image, 255, 0, 0); 
$green = imagecolorallocate($image, 0, 255, 0); 
  
// Draw a dashed line, 7 red pixels, 3 white pixels 
$style = array($red, $red, $red, $red, $red, $ren, $red, $green, $green, $green); 
imagesetstyle($image, $style); 
  
// Set the vertices of polygon 
$values = array( 
    150, 150, 
    450, 150, 
    150, 50, 
); 
  
// Draw the polygon 
imagepolygon($image, $values, 3, IMG_COLOR_STYLED); 
  
// Output image to the browser 
header('Content-type:image/png'); 
imagepng($image); 
?>輸出:

參考: https://www.php.net/manual/en/function.imagesetstyle.php
相關用法
- PHP each()用法及代碼示例
- p5.js pow()用法及代碼示例
- PHP next()用法及代碼示例
- PHP Ds\Set xor()用法及代碼示例
- PHP pow( )用法及代碼示例
- d3.js d3.map.set()用法及代碼示例
- CSS var()用法及代碼示例
- p5.js day()用法及代碼示例
- CSS url()用法及代碼示例
- p5.js second()用法及代碼示例
- p5.js hue()用法及代碼示例
- d3.js d3.set.has()用法及代碼示例
注:本文由純淨天空篩選整理自gurrrung大神的英文原創作品 PHP | imagesetstyle() function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。
