imagecopymerge()函數是PHP中的內置函數,用於將圖像複製並合並為單個圖像。如果成功,則此函數返回True;如果失敗,則返回False。
用法:
bool imagecopymerge ( $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。如果$pct = 0,則不執行任何操作;當$pct = 100時,此函數的行為類似於調色板圖像的imagecopy()函數,除了忽略alpha分量。它為真彩色圖像實現了alpha透明度。
返回值:如果成功,則此函數返回True;如果失敗,則返回False。
以下示例程序旨在說明PHP中的imagecopymerge()函數:
程序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 
imagecopymerge($dest, $src, 10, 10, 0, 0, 500, 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/col1.png'); 
  
// Copy and merge 
imagecopymerge($dest, $src, 10, 10, 0, 0, 500, 200, 75); 
  
// Output and free from memory 
header('Content-Type: image/png'); 
imagegif($dest); 
  
imagedestroy($dest); 
imagedestroy($src); 
?>輸出:

相關文章:
- PHP - imagecolorclosestalpha()用法及代碼示例
- PHP - imagecolorallocatealpha()用法及代碼示例
- PHP - imagecolorallocate()用法及代碼示例
參考: http://php.net/manual/en/function.imagecopymerge.php
相關用法
- PHP end()用法及代碼示例
- PHP each()用法及代碼示例
- d3.js d3.map.set()用法及代碼示例
- PHP abs()用法及代碼示例
- PHP Ds\Map put()用法及代碼示例
- PHP key()用法及代碼示例
- p5.js int()用法及代碼示例
- PHP pos()用法及代碼示例
- PHP sin( )用法及代碼示例
- CSS var()用法及代碼示例
- PHP cos( )用法及代碼示例
- p5.js red()用法及代碼示例
注:本文由純淨天空篩選整理自Mahadev99大神的英文原創作品 PHP | imagecopymerge() Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。
