简体   繁体   English

PHP GD将图像设置在透明图像后面

[英]PHP GD Set image behind transparent image

I need to put one image behind another image which is transparent. 我需要将一个图像放在另一个透明的图像后面。 Another way of explaining this is changing the priority of what is shown first. 解释此问题的另一种方法是更改​​显示的优先级。 Perhaps a layer? 也许是一层? My code puts background (bg.png) on top/in front of the transparent image (sig.png): 我的代码将背景(bg.png)放在透明图像(sig.png)的顶部/前面:

header( 'Content-Type: image/png' );

$im = imagecreatefromstring( file_get_contents( 'public/sig.png' ) );

imagealphablending( $im, true );

imagesavealpha( $im, true );

$temp = imagecreatefromstring( file_get_contents( 'public/bg.png' ) );

imagecopy( $im, $temp, 34, 88, 0, 0, 850, 300 );

imagepng( $im );

imagedestroy( $im );

Switching the first two parameters in your call to imagecopy will fix the draw order (you might need to update the other parameters too): 在调用imagecopy的调用中切换前两个参数将固定绘制顺序(您可能还需要更新其他参数):

imagecopy($temp, $im, 34, 88, 0, 0, 850, 300);
imagepng($temp);

As stated in the manual , imagecopy can be used to: 手册中所述, imagecopy可用于:

Copy a part of src_im onto dst_im ... src_im的一部分复制到dst_im ...

src_im is the second parameter, dst_im is the first parameter. src_im第二个参数, dst_im是第一个参数。

I created my custom image with transparent background as base and then merged two other images both background and main content together. 我创建了以透明背景为基础的自定义图像,然后将背景和主要内容的其他两个图像合并在一起。

Thank you. 谢谢。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM