PHP中的JPG透明PNG [英] Transparent PNG over JPG in PHP

查看:125
本文介绍了PHP中的JPG透明PNG的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

似乎很简单,不是:(

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

I'm trying to add something like a watermark (transparent png) on an image (jpg). This is the code I'm using:

$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, 200, 0, 0, $width, $height); 
header('Content-type: image/png');
imagepng($bottom_image);

当我合并图像时,png被定位在正确的地方,上面和左边的每一个都是好的(jpg被复制),但其他一切都是黑色的。

When I merge the images, the png is positioned at the right place, everythig above and left of it is good (jpg is copied), but everything else is black.

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

I've tried setting imagesavealpha and imagealphablending to false, there wasn't any difference.

您可以在 http://ekstrakt.selfip.com/photobomb/image.php

我在网上搜索过,我可以找不到解决方案。

I've searched around the net, I can't find a solution.

感谢任何帮助。

推荐答案

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

Your $width and $height should be the dimensions of the watermark, not of the photo. What you're telling it to do is copy the watermark with a much bigger size than it is. When it reads part of an image that doesn't exist (coordinates out of bounds) the result is opaque black, giving the result you see.

这篇关于PHP中的JPG透明PNG的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆