如何使用PHP将透明PNG与图像合并? [英] How to merge transparent PNG with image using PHP?

查看:119
本文介绍了如何使用PHP将透明PNG与图像合并?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

情况是这样的:我有一张50x50的小图片。我还有一个小的50x50透明图片,其中包含一个50x50 pic的帧,所以我基本上想把透明的png 放在图像的顶部并合并这两个会导致最后的第三张图片看起来像这样: http://img245.imageshack.us/i/50x50n.png

The situation is this: I have a small 50x50 pic. I also have a small 50x50 transparent picture which contains a frame for the 50x50 pic, so I basically want to put the transparent png on top of the image and merge those two which would lead to a final third picture that looks something like this: http://img245.imageshack.us/i/50x50n.png

注意:我不想仅使用HTML(我通过编写一个将透明png放在原始图像顶部的javascript插件来实现此目的) )。

Note: I don't want to do this using HTML only (I achieved this by writing a javascript plugin that put the transparent png on top of the original image).

谢谢。

推荐答案

你可以合并两张图片一起使用PHP GD2库。

You can merge the two images together using the PHP GD2 library.

示例:

<?php
 # If you don't know the type of image you are using as your originals.
 $image = imagecreatefromstring(file_get_contents($your_original_image));
 $frame = imagecreatefromstring(file_get_contents($your_frame_image));

 # If you know your originals are of type PNG.
 $image = imagecreatefrompng($your_original_image);
 $frame = imagecreatefrompng($your_frame_image);

 imagecopymerge($image, $frame, 0, 0, 0, 0, 50, 50, 100);

 # Save the image to a file
 imagepng($image, '/path/to/save/image.png');

 # Output straight to the browser.
 imagepng($image);
?>

这篇关于如何使用PHP将透明PNG与图像合并?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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