如何在 PHP 中使用 imagelayereffect() 函式將 Alpha 混合標誌設定為使用分層效果?


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

輸出

更新於: 2021年8月9日

99 次檢視

開啟你的 職業生涯

透過完成課程獲得認證

開始學習
廣告

© . All rights reserved.