Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> PHP

PHP – ตั้งค่า Alpha Blending Layer Effect ด้วย imagelayereffect()

ฟังก์ชัน imagelayereffect() ใช้ตั้งค่า alpha blending flag สำหรับ layering effects ต่างๆ

รูปแบบการใช้งาน (Syntax)

bool imagelayereffect(GdImage $image, int $effect)

พารามิเตอร์

  • $image – GdImage resource
  • $effect – effect constant:
    • IMG_EFFECT_REPLACE – pixel replacement (เหมือน imagealphablending true)
    • IMG_EFFECT_ALPHABLEND – normal pixel blending (เหมือน imagealphablending false)
    • IMG_EFFECT_NORMAL – เหมือน IMG_EFFECT_ALPHABLEND
    • IMG_EFFECT_OVERLAY – overlay effect: ขาวคงขาว ดำคงดำ สีเทาใช้สี foreground
    • IMG_EFFECT_MULTIPLY – multiply effect

ค่าที่คืนกลับ

คืน true เมื่อสำเร็จ false เมื่อล้มเหลว

ตัวอย่าง 1: OVERLAY Effect

<?php
$img = imagecreatetruecolor(700, 300);
imagefilledrectangle($img, 0, 0, 150, 150, imagecolorallocate($img, 122, 122, 122));
imagelayereffect($img, IMG_EFFECT_OVERLAY);
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));
header('Content-type: image/png');
imagepng($img);
imagedestroy($img);
?>

ผลลัพธ์

PHP – ตั้งค่า Alpha Blending Layer Effect ด้วย imagelayereffect()

ตัวอย่าง 2: REPLACE Effect

<?php
$img = imagecreatetruecolor(700, 200);
imagefilledrectangle($img, 0, 0, 200, 200, imagecolorallocate($img, 122, 122, 122));
imagelayereffect($img, IMG_EFFECT_REPLACE);
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));
header('Content-type: image/png');
imagepng($img);
imagedestroy($img);
?>

ผลลัพธ์

PHP – ตั้งค่า Alpha Blending Layer Effect ด้วย imagelayereffect()