将PNG放在PHP中的JPG上 [英] Put PNG over a JPG in PHP

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

问题描述

我想在PHP中执行以下操作:

I want to do the following in PHP:

我有两个图像,一个jpg和一个png。我想将jpg的大小调整为与png相同的大小,然后将png置于顶部。 PNG具有透明度,所以我想保留它,以便jpg显示在下面。

I have two images, a jpg and a png. I want to resize the jpg to the same size as the png then put the png on top. The PNG has transparency so I would like to preserve that so the jpg shows underneath.

如果有人可以提供帮助那就太棒了!

If anyone could help that would be great!

谢谢

推荐答案

<?
$png = imagecreatefrompng('./mark.png');
$jpeg = imagecreatefromjpeg('./image.jpg');

list($width, $height) = getimagesize('./image.jpg');
list($newwidth, $newheight) = getimagesize('./mark.png');
$out = imagecreatetruecolor($newwidth, $newheight);
imagecopyresampled($out, $jpeg, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
imagecopyresampled($out, $png, 0, 0, 0, 0, $newwidth, $newheight, $newwidth, $newheight);
imagejpeg($out, 'out.jpg', 100);
?>

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

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