imagelayereffect
Description
The imagelayereffect of Image for PHP sets the alpha blending flag to use layering effects.
Syntax
imagelayereffect(
GdImage $image,
int $effect
): boolParameters
image
A GdImage object, returned by one of the image creation functions, such as imagecreatetruecolor().
effect
One of the following constants:
| Constant | Description |
|---|---|
| IMG_EFFECT_REPLACE | Use pixel replacement. |
| IMG_EFFECT_ALPHABLEND | Use normal pixel blending. |
| IMG_EFFECT_NORMAL | Same as IMG_EFFECT_ALPHABLEND. |
| IMG_EFFECT_OVERLAY | Overlay has the effect that black background pixels will remain black, white background pixels will remain white, but gray background pixels will take the color of the foreground pixel. |
| IMG_EFFECT_MULTIPLY | Overlays with a multiply effect. |
Return
Returns true on success or false on failure.
Examples
1 · return
<? $width = 100; $height = 100; $image = imagecreate($width, $height); $effect = IMG_EFFECT_NORMAL; $return = imagelayereffect($image, $effect); var_export($return);
true
2 · base64 · effect · IMG_EFFECT_REPLACE
<?
$width = 100;
$height = 100;
$image = imagecreatetruecolor($width, $height);
$effect = IMG_EFFECT_REPLACE;
imagelayereffect($image, $effect);
$red = 128;
$green = 128;
$blue = 128;
$alpha = 64;
$color = imagecolorallocatealpha($image, $red, $green, $blue, $alpha);
$x = 0;
$y = 0;
imagefill($image, $x, $y, $color);
$red = 255;
$green = 0;
$blue = 0;
$alpha = 64;
$color = imagecolorallocatealpha($image, $red, $green, $blue, $alpha);
$x1 = 0;
$y1 = 0;
$x2 = 50;
$y2 = 50;
imagefilledrectangle($image, $x1, $y1, $x2, $y2, $color);
$red = 0;
$green = 255;
$blue = 0;
$alpha = 64;
$color = imagecolorallocatealpha($image, $red, $green, $blue, $alpha);
$x1 = 25;
$y1 = 25;
$x2 = 75;
$y2 = 75;
imagefilledrectangle($image, $x1, $y1, $x2, $y2, $color);
$red = 0;
$green = 0;
$blue = 255;
$alpha = 64;
$color = imagecolorallocatealpha($image, $red, $green, $blue, $alpha);
$x1 = 50;
$y1 = 50;
$x2 = 100;
$y2 = 100;
imagefilledrectangle($image, $x1, $y1, $x2, $y2, $color);
ob_start();
imagepng($image);
$output = ob_get_clean();
echo '<!doctype html>
<html>
<body>
<img src="data:image/png;base64,' . base64_encode($output) . '">
</body>
</html>';
<!doctype html>
<html>
<body>
<img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAGQAAABkCAIAAAD/gAIDAAAACXBIWXMAAA7EAAAOxAGVKw4bAAABEUlEQVR4nO3bMQrDMBAAQTv44fLL4z7dwIEV2HnAIRapOnR+j03da719hF+ftw/wT4oFigWKBYoFigWKBYoFigWKBYoFigWKBYoFigWKBYoFigWKBYoFigWKBYoFigXOwSXr5KxR614jc7pZoFigWKBYoFigWKBYoFigWKBYoFigWKBYoFigWKBYoFigWKBYoFigWKBYoFigWGDXJeuWC9tr9Hft4Kgd9QxBsUCxQLFAsUCxQLFAsUCxQLFAsUCxQLFAsUCxQLFAsUCxQLFAsUCxQLFAsUCxwDU4a+p37bHrtrabBYoFigWKBYoFigWKBYoFigWKBYoFigWKBYoFigWKBYoFigWKBYoFigWKBYoFHg2HDcsLZlWkAAAAAElFTkSuQmCC">
</body>
</html>3 · base64 · effect · IMG_EFFECT_ALPHABLEND
<?
$width = 100;
$height = 100;
$image = imagecreatetruecolor($width, $height);
$effect = IMG_EFFECT_ALPHABLEND;
imagelayereffect($image, $effect);
$red = 128;
$green = 128;
$blue = 128;
$alpha = 64;
$color = imagecolorallocatealpha($image, $red, $green, $blue, $alpha);
$x = 0;
$y = 0;
imagefill($image, $x, $y, $color);
$red = 255;
$green = 0;
$blue = 0;
$alpha = 64;
$color = imagecolorallocatealpha($image, $red, $green, $blue, $alpha);
$x1 = 0;
$y1 = 0;
$x2 = 50;
$y2 = 50;
imagefilledrectangle($image, $x1, $y1, $x2, $y2, $color);
$red = 0;
$green = 255;
$blue = 0;
$alpha = 64;
$color = imagecolorallocatealpha($image, $red, $green, $blue, $alpha);
$x1 = 25;
$y1 = 25;
$x2 = 75;
$y2 = 75;
imagefilledrectangle($image, $x1, $y1, $x2, $y2, $color);
$red = 0;
$green = 0;
$blue = 255;
$alpha = 64;
$color = imagecolorallocatealpha($image, $red, $green, $blue, $alpha);
$x1 = 50;
$y1 = 50;
$x2 = 100;
$y2 = 100;
imagefilledrectangle($image, $x1, $y1, $x2, $y2, $color);
ob_start();
imagepng($image);
$output = ob_get_clean();
echo '<!doctype html>
<html>
<body>
<img src="data:image/png;base64,' . base64_encode($output) . '">
</body>
</html>';
<!doctype html>
<html>
<body>
<img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAGQAAABkCAIAAAD/gAIDAAAACXBIWXMAAA7EAAAOxAGVKw4bAAABOUlEQVR4nO3bsWkDQRBAUdmoA3dxoYq5Xhwpcy3i1IC7uEg1XBvOlX0YkAXvFTAsn91o2I/Hspz+pfu6vvoIzz5ffYB3IlYgViBWIFYgViBWIFYgViBWIFYgViBWIFYgViBWIFYgViBWIFYgViBWIFYgVnAenPXzfQxO2y/b1Kj1PrOvdbMCsQKxArECsQKxArECsQKxArECsQKxArECsQKxArECsQKxArECsQKxArECsQKxgskl66D9dj1+v6ambftlZM558Hft4A55sNQgzzAQKxArECsQKxArECsQKxArECsQKxArECsQKxArECsQKxArECsQKxArECsQKxArmNxIT/2uPc3tkGe5WYFYgViBWIFYgViBWIFYgViBWIFYgViBWIFYgViBWIFYgViBWIFYgViBWIFYwR/JLxVBirordAAAAABJRU5ErkJggg==">
</body>
</html>4 · base64 · effect · IMG_EFFECT_NORMAL
<?
$width = 100;
$height = 100;
$image = imagecreatetruecolor($width, $height);
$effect = IMG_EFFECT_NORMAL;
imagelayereffect($image, $effect);
$red = 128;
$green = 128;
$blue = 128;
$alpha = 64;
$color = imagecolorallocatealpha($image, $red, $green, $blue, $alpha);
$x = 0;
$y = 0;
imagefill($image, $x, $y, $color);
$red = 255;
$green = 0;
$blue = 0;
$alpha = 64;
$color = imagecolorallocatealpha($image, $red, $green, $blue, $alpha);
$x1 = 0;
$y1 = 0;
$x2 = 50;
$y2 = 50;
imagefilledrectangle($image, $x1, $y1, $x2, $y2, $color);
$red = 0;
$green = 255;
$blue = 0;
$alpha = 64;
$color = imagecolorallocatealpha($image, $red, $green, $blue, $alpha);
$x1 = 25;
$y1 = 25;
$x2 = 75;
$y2 = 75;
imagefilledrectangle($image, $x1, $y1, $x2, $y2, $color);
$red = 0;
$green = 0;
$blue = 255;
$alpha = 64;
$color = imagecolorallocatealpha($image, $red, $green, $blue, $alpha);
$x1 = 50;
$y1 = 50;
$x2 = 100;
$y2 = 100;
imagefilledrectangle($image, $x1, $y1, $x2, $y2, $color);
ob_start();
imagepng($image);
$output = ob_get_clean();
echo '<!doctype html>
<html>
<body>
<img src="data:image/png;base64,' . base64_encode($output) . '">
</body>
</html>';
<!doctype html>
<html>
<body>
<img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAGQAAABkCAIAAAD/gAIDAAAACXBIWXMAAA7EAAAOxAGVKw4bAAABOUlEQVR4nO3bsWkDQRBAUdmoA3dxoYq5Xhwpcy3i1IC7uEg1XBvOlX0YkAXvFTAsn91o2I/Hspz+pfu6vvoIzz5ffYB3IlYgViBWIFYgViBWIFYgViBWIFYgViBWIFYgViBWIFYgViBWIFYgViBWIFYgVnAenPXzfQxO2y/b1Kj1PrOvdbMCsQKxArECsQKxArECsQKxArECsQKxArECsQKxArECsQKxArECsQKxArECsQKxgskl66D9dj1+v6ambftlZM558Hft4A55sNQgzzAQKxArECsQKxArECsQKxArECsQKxArECsQKxArECsQKxArECsQKxArECsQKxArmNxIT/2uPc3tkGe5WYFYgViBWIFYgViBWIFYgViBWIFYgViBWIFYgViBWIFYgViBWIFYgViBWIFYwR/JLxVBirordAAAAABJRU5ErkJggg==">
</body>
</html>5 · base64 · effect · IMG_EFFECT_OVERLAY
<?
$width = 100;
$height = 100;
$image = imagecreatetruecolor($width, $height);
$effect = IMG_EFFECT_OVERLAY;
imagelayereffect($image, $effect);
$red = 128;
$green = 128;
$blue = 128;
$alpha = 64;
$color = imagecolorallocatealpha($image, $red, $green, $blue, $alpha);
$x = 0;
$y = 0;
imagefill($image, $x, $y, $color);
$red = 255;
$green = 0;
$blue = 0;
$alpha = 64;
$color = imagecolorallocatealpha($image, $red, $green, $blue, $alpha);
$x1 = 0;
$y1 = 0;
$x2 = 50;
$y2 = 50;
imagefilledrectangle($image, $x1, $y1, $x2, $y2, $color);
$red = 0;
$green = 255;
$blue = 0;
$alpha = 64;
$color = imagecolorallocatealpha($image, $red, $green, $blue, $alpha);
$x1 = 25;
$y1 = 25;
$x2 = 75;
$y2 = 75;
imagefilledrectangle($image, $x1, $y1, $x2, $y2, $color);
$red = 0;
$green = 0;
$blue = 255;
$alpha = 64;
$color = imagecolorallocatealpha($image, $red, $green, $blue, $alpha);
$x1 = 50;
$y1 = 50;
$x2 = 100;
$y2 = 100;
imagefilledrectangle($image, $x1, $y1, $x2, $y2, $color);
ob_start();
imagepng($image);
$output = ob_get_clean();
echo '<!doctype html>
<html>
<body>
<img src="data:image/png;base64,' . base64_encode($output) . '">
</body>
</html>';
<!doctype html>
<html>
<body>
<img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAGQAAABkCAIAAAD/gAIDAAAACXBIWXMAAA7EAAAOxAGVKw4bAAABKUlEQVR4nO3bQYrDMBAAQcnk38YPzzr33BoG4oWqBwyiLZ8G7Xvv9UjXef76CN+OXx/gPxErECsQKxArECsQKxArECsQKxArECsQKxArECsQKxArECsQKxArECsQKxArECvYk0vWfY+NWut4jx3svGb2tW5WIFYgViBWIFYgViBWIFYgViBWIFYgViBWIFYgViBWIFYgViBWIFYgViBWIFYgVvDUJevf2vfYh9zHe2TOa/B17XVeU6Pu9cTHyH7DQKxArECsQKxArECsQKxArECsQKxArECsQKxArECsQKxArECsQKxArECsQKxArOA1OGvqde1a65obNcjNCsQKxArECsQKxArECsQKxArECsQKxArECsQKxArECsQKxArECsQKxArECsQKPt8oE8t0PSTuAAAAAElFTkSuQmCC">
</body>
</html>6 · base64 · effect · IMG_EFFECT_MULTIPLY
<?
$width = 100;
$height = 100;
$image = imagecreatetruecolor($width, $height);
$effect = IMG_EFFECT_MULTIPLY;
imagelayereffect($image, $effect);
$red = 128;
$green = 128;
$blue = 128;
$alpha = 64;
$color = imagecolorallocatealpha($image, $red, $green, $blue, $alpha);
$x = 0;
$y = 0;
imagefill($image, $x, $y, $color);
$red = 255;
$green = 0;
$blue = 0;
$alpha = 64;
$color = imagecolorallocatealpha($image, $red, $green, $blue, $alpha);
$x1 = 0;
$y1 = 0;
$x2 = 50;
$y2 = 50;
imagefilledrectangle($image, $x1, $y1, $x2, $y2, $color);
$red = 0;
$green = 255;
$blue = 0;
$alpha = 64;
$color = imagecolorallocatealpha($image, $red, $green, $blue, $alpha);
$x1 = 25;
$y1 = 25;
$x2 = 75;
$y2 = 75;
imagefilledrectangle($image, $x1, $y1, $x2, $y2, $color);
$red = 0;
$green = 0;
$blue = 255;
$alpha = 64;
$color = imagecolorallocatealpha($image, $red, $green, $blue, $alpha);
$x1 = 50;
$y1 = 50;
$x2 = 100;
$y2 = 100;
imagefilledrectangle($image, $x1, $y1, $x2, $y2, $color);
ob_start();
imagepng($image);
$output = ob_get_clean();
echo '<!doctype html>
<html>
<body>
<img src="data:image/png;base64,' . base64_encode($output) . '">
</body>
</html>';
<!doctype html>
<html>
<body>
<img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAGQAAABkCAIAAAD/gAIDAAAACXBIWXMAAA7EAAAOxAGVKw4bAAABNUlEQVR4nO3bsYlCQRRA0a8I24LZT38HW4/lbRcfrMHcwCIMzTc78ECFewp4DJeZ6DGH/XJZPtK+ru8+wn/Hdx/gmxQLFAsUCxQLFAsUCxQLFAsUCxQLFAsUCxQLFAsUCxQLFAsUCxQLFAsUCxQLFAucBmf9bY/Bac/fsVHrPrOv7WaBYoFigWKBYoFigWKBYoFigWKBYoFigWKBYoFigWKBYoFigWKBYoFigWKBYoFigckl66Db9fxz38bGDS1sT4O/awd3yJOl5vQMQbFAsUCxQLFAsUCxQLFAsUCxQLFAsUCxQLFAsUCxQLFAsUCxQLFAsUCxQLFAscDkRnrqd+2yjC5s53SzQLFAsUCxQLFAsUCxQLFAsUCxQLFAsUCxQLFAsUCxQLFAsUCxQLFAsUCxQLHACykBEIncgNtXAAAAAElFTkSuQmCC">
</body>
</html>Links
Image
- gd_info
- getimagesize
- getimagesizefromstring
- image_type_to_extension
- image_type_to_mime_type
- imageaffine
- imageaffinematrixconcat
- imageaffinematrixget
- imagealphablending
- imageantialias
- imagearc
- imageavif
- imagebmp
- imagechar
- imagecharup
- imagecolorallocate
- imagecolorallocatealpha
- imagecolorat
- imagecolorclosest
- imagecolorclosestalpha
- imagecolorclosesthwb
- imagecolordeallocate
- imagecolorexact
- imagecolorexactalpha
- imagecolormatch
- imagecolorresolve
- imagecolorresolvealpha
- imagecolorset
- imagecolorsforindex
- imagecolorstotal
- imagecolortransparent
- imageconvolution
- imagecopy
- imagecopymerge
- imagecopymergegray
- imagecopyresampled
- imagecopyresized
- imagecreate
- imagecreatefromavif
- imagecreatefrombmp
- imagecreatefromgif
- imagecreatefromjpeg
- imagecreatefrompng
- imagecreatefromstring
- imagecreatefromtga
- imagecreatefromwbmp
- imagecreatefromwebp
- imagecreatefromxbm
- imagecreatefromxpm
- imagecreatetruecolor
- imagecrop
- imagecropauto
- imagedashedline
- imagedestroy
- imageellipse
- imagefill
- imagefilledarc
- imagefilledellipse
- imagefilledpolygon
- imagefilledrectangle
- imagefilltoborder
- imagefilter
- imageflip
- imagefontheight
- imagefontwidth
- imageftbbox
- imagefttext
- imagegammacorrect
- imagegetclip
- imagegetinterpolation
- imagegif
- imageinterlace
- imageistruecolor
- imagejpeg
- imageline
- imageloadfont
- imageopenpolygon
- imagepalettecopy
- imagepalettetotruecolor
- imagepng
- imagepolygon
- imagerectangle
- imageresolution
- imagerotate
- imagesavealpha
- imagescale
- imagesetbrush
- imagesetclip
- imagesetinterpolation
- imagesetpixel
- imagesetstyle
- imagesetthickness
- imagesettile
- imagestring
- imagestringup
- imagesx
- imagesy
- imagetruecolortopalette
- imagettfbbox
- imagettftext
- imagetypes
- imagewbmp
- imagewebp
- imagexbm
- iptcembed
- iptcparse