imagelayereffect()是 PHP 中的一個內置函數,用於設置 alpha 混合標誌以使用分層效果。它在成功時返回 True 或在失敗時返回 False。
用法
bool imagelayereffect($image, $effect)
參數
imagelayereffect()需要兩個不同的參數:$image和$effect。
$image− 該參數由圖像創建函數imagecreatetruecolor() 返回。它用於創建圖像的大小。
$effect- 此參數用於設置混合標誌的值,使用不同的效果常量,如下所示 -
IMG_EFFECT_REPLACE− 用於設置像素替換。它更類似於將 true 傳遞給 imagealphablending() 函數。
IMG_EFFETC_ALPHABLEND− 用於設置正常像素混合。這相當於將 false 傳遞給 imagealphablending() 函數。
IMG_EFFECT_NORMAL− 與IMG_EFFETC_ALPHABLEND 相同。
IMG_EFFETC_OVERLAY− 通過使用 IMG_EFFECT_OVERLAY,白色背景像素將保持白色,黑色背景像素將保持黑色,但灰色背景像素將采用前景像素的顏色。
IMG_EFFETC_MULTIPLY- 這將設置乘法效果。
返回值
imagelayereffect()成功時返回 True,失敗時返回 False。
例子1
<?php
// Setup an image using imagecreatetruecolor() function
$img = imagecreatetruecolor(700, 300);
// Set a background color
imagefilledrectangle($img, 0, 0, 150, 150, imagecolorallocate($img, 122, 122, 122));
// Apply the overlay alpha blending flag
imagelayereffect($img, IMG_EFFECT_OVERLAY);
// Draw two grey ellipses
imagefilledellipse($img, 50, 50, 40, 40, imagecolorallocate($img, 100, 255, 100));
imagefilledellipse($img, 50, 50, 50, 80, imagecolorallocate($img, 100, 100, 255));
imagefilledellipse($img, 50, 50, 80, 50, imagecolorallocate($img, 255, 0, 0));
// Output image
header('Content-type:image/png');
imagepng($img);
imagedestroy($img);
?>
輸出
例子2
<?php
// Setup an image using imagecreatetruecolor() function.
$img = imagecreatetruecolor(700, 200);
// Set a background color
imagefilledrectangle($img, 0, 0, 200, 200, imagecolorallocate($img, 122, 122, 122));
// Apply the overlay alpha blending flag
imagelayereffect($img, IMG_EFFECT_REPLACE);
// Draw two grey ellipses
imagefilledellipse($img,100,100,160,160, imagecolorallocate($img,0,0,0));
imagefilledellipse($img,100,100,140,140, imagecolorallocate($img,0,0,255));
imagefilledellipse($img,100,100,100,100, imagecolorallocate($img,255,0,0));
// Output image
header('Content-type:image/png');
imagepng($img);
imagedestroy($img);
?>
輸出
相關用法
- PHP imagegif()用法及代碼示例
- PHP imageresolution()用法及代碼示例
- PHP imagebmp()用法及代碼示例
- PHP imagearc()用法及代碼示例
- PHP imageftbbox()用法及代碼示例
- PHP imagecreatefromgif()用法及代碼示例
- PHP imagecreatefrombmp()用法及代碼示例
- PHP imagecreatefromstring()用法及代碼示例
- PHP imagestring()用法及代碼示例
- PHP imagecreatetruecolor()用法及代碼示例
- PHP imagecrop()用法及代碼示例
- PHP imagecreatefrompng()用法及代碼示例
- PHP imagecolorat()用法及代碼示例
- PHP imagesetbrush()用法及代碼示例
- PHP imagecolorset()用法及代碼示例
- PHP imagecreatefromxpm()用法及代碼示例
- PHP imagelayereffect()用法及代碼示例
- PHP imageline()用法及代碼示例
- PHP imageflip()用法及代碼示例
- PHP imagecolorresolve()用法及代碼示例
注:本文由純淨天空篩選整理自Urmila Samariya大神的英文原創作品 How to set the alpha blending flag to use layering effects using imaglayereffect() function in PHP?。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。