imagepalettecopy()函數是PHP中的內置函數,用於將調色板從一個圖像複製到另一個圖像。
用法:
void imagepalettecopy( resource $destination, resource $source )
參數:該函數接受上述和以下描述的兩個參數:
- $destination:它指定目標圖像資源。
- $source:它指定源圖像資源。
返回值:此函數不返回任何內容。
下麵給出的程序說明了PHP中的imagepalettecopy()函數:
程序1:
<?php
// Create two palette images
$palette1 = imagecreate(700, 200);
$palette2 = imagecreate(700, 200);
// Create a green color
$green = imagecolorallocate($palette1, 0, 255, 0);
// Add green color as background to pallete 1
imagefilledrectangle($palette1, 0, 0, 99, 99, $green);
// Copy the palette from image 1 to image 2
imagepalettecopy($palette2, $palette1);
// Output image to the browser and see the color is green
header('Content-type:image/png');
imagepng($palette2);
?>
輸出:
程序2:
<?php
// Create two palette images
$palette1 = imagecreate(700, 200);
$palette2 = imagecreate(700, 200);
// Create a green color
$green = imagecolorallocate($palette1, 0, 255, 0);
// Add green color as background to pallete 1
imagefilledrectangle($palette1, 0, 0, 99, 99, $green);
// Copy the palette from image 1 to image 2
imagepalettecopy($palette2, $palette1);
// Get the number of colors in image
$color1 = imagecolorstotal($palette1);
$color2 = imagecolorstotal($palette2);
echo "Number of colors at image 1 is " . $color1 . "<br>";
echo "Number of colors at image 2 is " . $color2;
?>
輸出:
Number of colors at image 1 is 1 Number of colors at image 2 is 1
參考: https://www.php.net/manual/en/function.imagepalettecopy.php
相關用法
- PHP pow( )用法及代碼示例
- d3.js d3.map.set()用法及代碼示例
- p5.js pow()用法及代碼示例
- PHP each()用法及代碼示例
- PHP next()用法及代碼示例
- PHP Ds\Set xor()用法及代碼示例
- p5.js hue()用法及代碼示例
- p5.js hex()用法及代碼示例
- CSS var()用法及代碼示例
- p5.js day()用法及代碼示例
- CSS url()用法及代碼示例
- p5.js value()用法及代碼示例
注:本文由純淨天空篩選整理自gurrrung大神的英文原創作品 PHP | imagepalettecopy() function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。