當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


PHP imagelayereffect()用法及代碼示例

imagelayereffect()函數是PHP中的內置函數,用於設置alpha混合標誌以使用分層效果。如果成功,此函數返回True;如果失敗,則返回False。

用法:

bool imagelayereffect( $image, $effect )

參數:該函數接受上述和以下描述的兩個參數:


  • $image:它由圖像創建函數之一(例如imagecreatetruecolor())返回。它用於創建圖像的尺寸。
  • $effect:此參數設置效果常數的值。效果常數的值如下所示:
    • IMG_EFFECT_REPLACE:用於設置像素替換。等效於將True傳遞給imagealphablending()函數。
    • IMG_EFFECT_ALPHABLEND:用於設置普通像素混合。等效於將False傳遞給imagealphablending()函數。
    • IMG_EFFECT_NORMAL:與IMG_EFFECT_ALPHABLEND相同。
    • IMG_EFFECT_OVERLAY:這是黑色背景像素將保持黑色,白色背景像素將保持白色而灰色背景像素將采用前景像素顏色的效果。
    • IMG_EFFECT_MULTIPLY:設置乘法效果。

返回值:如果成功,此函數返回True;如果失敗,則返回False。

以下示例程序旨在說明PHP中的imagelayereffect()函數:

示例1:

<?php 
// Setup an image 
$im = imagecreatetruecolor(200, 200); 
  
// Set a background 
imagefilledrectangle($im, 0, 0, 200, 200, imagecolorallocate($im, 220, 220, 220)); 
  
// Apply the overlay alpha blending flag 
imagelayereffect($im, IMG_EFFECT_OVERLAY); 
  
// Draw two grey ellipses 
imagefilledellipse($im, 100, 100, 160, 160, imagecolorallocate($im, 100, 255, 100)); 
imagefilledellipse($im, 100, 100, 140, 140, imagecolorallocate($im, 100, 100, 255)); 
imagefilledellipse($im, 100, 100, 100, 100, imagecolorallocate($im, 255, 100, 100)); 
  
// Output 
header('Content-type: image/png'); 
  
imagepng($im); 
imagedestroy($im); 
?>

輸出:

示例2:

<?php 
// Setup an image 
$im = imagecreatetruecolor(200, 200); 
  
// Set a background 
imagefilledrectangle($im, 0, 0, 200, 200, imagecolorallocate($im, 220, 220, 220)); 
  
// Apply the overlay alpha blending flag 
imagelayereffect($im, IMG_EFFECT_REPLACE); 
  
// Draw two grey ellipses 
imagefilledellipse($im, 100, 100, 160, 160, imagecolorallocate($im, 100, 255, 100)); 
imagefilledellipse($im, 100, 100, 140, 140, imagecolorallocate($im, 100, 100, 255)); 
imagefilledellipse($im, 100, 100, 100, 100, imagecolorallocate($im, 255, 100, 100)); 
  
// Output 
header('Content-type: image/png'); 
  
imagepng($im); 
imagedestroy($im); 
?>

輸出:

參考: http://php.net/manual/en/function.imagelayereffect.php



相關用法


注:本文由純淨天空篩選整理自Vishal_Khoda大神的英文原創作品 PHP | imagelayereffect() Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。