用PHP叠加图像 [英] Superimpose Images with PHP

查看:82
本文介绍了用PHP叠加图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一种在现有图像上叠加图像的方法。

I am searching for a way to overlay an image on an existing image.

例如:

+

我在这里找到了一个很好的例子:使用一个图像元素进行PNG覆盖。
但我有两个问题。

I have found a great example over here: PNG overlay using one single Image element. but I have two problems with these.

首先,我不希望维度彼此相等。例如(215 * 215 215 * 215)。这是因为我的用户可以选择他们想要放置图像的位置。 (顶部,左侧,底部,右上角)8个方向。

First of all, I don't want the dimensions to be equal to each other. e.g (215*215 on 215*215). This is because my users would have the ability to choose where they want to put their image. (Top, left, bottom, top-right) so 8 directions.

第二个问题是,在该示例中,只有2个图像是允许叠加。我的用户(再次)将能够在其上放置多个图像。

The second problem is that in that example, only 2 images are allowed to overlay. My users (again) will have the ability to put multiple images on top of it.

我对Javascript和PHP有一点了解,所以如果你的话会很棒男人(和女孩)可以帮助我。

I have a little knowledge of Javascript and PHP, so it would be great if you guys (and girls) could help me out.

真诚地,

推荐答案

您可以使用 GD 库执行此操作。有合并功能的功能称为 imagecopymerge

You can do this using GD library. There is function to "merge" images called imagecopymerge.

以下是合并图像的一个非常简单的示例:

Here is a very simple example how to merge images:

<?php
header('Content-Type: image/jpeg');

$bg = imagecreatefromjpeg('background.jpg');
$img = imagecreatefromjpeg('image.jpg');

imagecopymerge($bg, $img, 0, 0, 0, 0, imagesx($bg), imagesy($bg), 75);

imagejpeg($bg, null, 100);
?>

这篇关于用PHP叠加图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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