javascript 使用 PHP 叠加图像
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6547784/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Superimpose Images with PHP
提问by Verhelst
I am searching for a way to overlay an image on an existing image.
我正在寻找一种在现有图像上叠加图像的方法。
e.g:
例如:
+
+
I have found a great example over here: PNG overlay using one single Image element.but I have twoproblems with these.
我在这里找到了一个很好的例子:使用单个 Image 元素的 PNG 覆盖。但我有两个问题。
Firstof 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.
首先,我不希望尺寸彼此相等。例如(215*215 上的 215*215)。这是因为我的用户可以选择他们想要放置图像的位置。(上、左、下、右上)所以 8 个方向。
The secondproblem 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.
的第二问题是,在该例子中,只有2个图像被允许为叠加。我的用户(再次)将能够在其上放置多个图像。
I have a little knowledge of Javascript and PHP, so it would be great if you guys (and girls) could help me out.
我对 Javascript 和 PHP 有一点了解,所以如果你们(和女孩)能帮助我,那就太好了。
Sincerely,
真挚地,
回答by Robik
You can do this using GDlibrary. There is function to "merge" images called imagecopymerge
.
您可以使用GD库执行此操作。有一个名为“合并”图像的功能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);
?>