加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

PHP中的JPG透明PNG

发布时间:2020-12-13 13:46:46 所属栏目:PHP教程 来源:网络整理
导读:什么似乎很简单,不是:( 我试图在图像(jpg)上添加类似水印(透明png)的东西. 这是我正在使用的代码: $width = 800; $height = 600; $bottom_image = imagecreatefromjpeg("portrait1.jpg"); $top_image = imagecreatefrompng("man2.png"); imagesavealpha($to
什么似乎很简单,不是:(

我试图在图像(jpg)上添加类似水印(透明png)的东西.
这是我正在使用的代码:

$width = 800; 
$height = 600; 
$bottom_image = imagecreatefromjpeg("portrait1.jpg"); 
$top_image = imagecreatefrompng("man2.png"); 
imagesavealpha($top_image,true); 
imagealphablending($top_image,true); 
imagecopy($bottom_image,$top_image,200,$width,$height); 
header('Content-type: image/png');
imagepng($bottom_image);

当我合并图像时,png位于正确的位置,它的上方和左侧都是好的(jpg被复制),但其他一切都是黑色的.

我已经尝试将imagesavealpha和imagealphablending设置为false,没有任何区别.

您可以在http://ekstrakt.selfip.com/photobomb/image.php看到生成的图像

我在网上搜索,我找不到解决方案.

任何帮助表示赞赏.

你的$width和$height应该是水印的尺寸,而不是照片的尺寸.你告诉它要做的是复制比它大得多的水印.当它读取不存在的图像的一部分(坐标超出界限)时,结果是不透明的黑色,给出您看到的结果.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读