当前位置: 首页>>编程示例 >>用法及示例精选 >>正文


PHP imaglayereffect()用法及代码示例

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);
?>

输出

相关用法


注:本文由纯净天空筛选整理自Urmila Samariya大神的英文原创作品 How to set the alpha blending flag to use layering effects using imaglayereffect() function in PHP?。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。