imagecopymergegray()函數是PHP中的內置函數,用於複製和合並帶有灰度的圖像部分。此函數將源圖像的一部分複製到目標圖像。成功時此函數返回true,失敗時返回false。
用法:
bool imagecopymergegray ( $dst_image, $src_image, $dst_x, $dst_y, $src_x, $src_y, $src_w, $src_h, $pct )
參數:此函數接受上述和以下所述的九個參數:
- $dst_image:此參數用於設置目標圖像鏈接資源。
- $src_image:此參數用於設置源圖像鏈接資源。
- $dst_x:此參數用於設置目標點的x坐標。
- $dst_y:此參數用於設置目標點的y坐標。
- $src_x:此參數用於設置源點的x坐標。
- $src_y:此參數用於設置源點的x坐標。
- $src_w:此參數用於設置源寬度。
- $src_h:此參數用於設置光源高度。
- $pct:此參數用於根據$pct更改灰度。 $pct的範圍是0到100,其中0是完全灰度,而100則保持不變。如果$pct = 0,則不執行任何操作;當$pct = 100時,此函數的行為類似於調色板圖像的imagecopy()函數,除了忽略alpha分量。它為真彩色圖像實現了alpha透明度。
返回值:成功時此函數返回true,失敗時返回false。
以下示例程序旨在說明PHP中的imagecopymergegray()函數:
程序1:
<?php
// Create image instances
$dest = imagecreatefromgif(
'https://media.geeksforgeeks.org/wp-content/uploads/animateImages.gif');
$src = imagecreatefromgif(
'https://media.geeksforgeeks.org/wp-content/uploads/slider.gif');
// Copy and merge the image
imagecopymergegray($dest, $src, 10, 10, 0, 0, 700, 200, 75);
// Output and free from memory
header('Content-Type: image/gif');
imagegif($dest);
imagedestroy($dest);
imagedestroy($src);
?>
輸出:
程序2:
<?php
// Create image instances
$dest = imagecreatefrompng(
'https://media.geeksforgeeks.org/wp-content/uploads/geeksforgeeks-9.png');
$src = imagecreatefrompng(
'https://media.geeksforgeeks.org/wp-content/uploads/temp1.png');
// Copy and merge
imagecopymergegray($dest, $src, 10, 10, 0, 0, 700, 200, 75);
// Output and free from memory
header('Content-Type: image/png');
imagegif($dest);
imagedestroy($dest);
imagedestroy($src);
?>
輸出:
相關文章:
參考: http://php.net/manual/en/function.imagecopymergegray.php
相關用法
- CSS var()用法及代碼示例
- p5.js str()用法及代碼示例
- p5.js pow()用法及代碼示例
- p5.js day()用法及代碼示例
- d3.js d3.map.set()用法及代碼示例
- PHP Ds\Map put()用法及代碼示例
- d3.js d3.map.has()用法及代碼示例
- PHP next()用法及代碼示例
- p5.js sq()用法及代碼示例
- p5.js value()用法及代碼示例
- p5.js hex()用法及代碼示例
- PHP Ds\Set xor()用法及代碼示例
注:本文由純淨天空篩選整理自Mahadev99大神的英文原創作品 PHP | imagecopymergegray() Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。