如何通过PHP将3个图像合并为1个图像? [英] How can I merge 3 images into 1 image via PHP?

查看:139
本文介绍了如何通过PHP将3个图像合并为1个图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我真的找不到成功做到这一点的方法..我搜索谷歌这个,它或者在图像周围有黑色阴影或者所有图像都没有重叠。你能帮忙吗?

I really cannot find a way to successfully do it.. I've searched google for this and it either has black shades around the images or all the images don't overlap. Could you please help?

我对PHP很好;我会给自己一个2/5 ..如果有人愿意帮我,我真的很感激。

I am alright at PHP; I'd give myself a 2/5.. I would really appreciate if someone would be willing to help me out.

我正在寻找一个简单的api类似于:

I'm looking for a simple api that goes something like:

$color=$_GET['color'];
$face=$_GET['face'];
$hat=$_GET['hat'];

echo '<img src="avatar.php?color=$color&face=$face&hat=$hat">';

感谢提前的任何帮助。我也可以从我对其他语言的知识中理解php,所以不要害怕与我交谈技术;但不是太技术性。

Thanks for any help in advance. I can understand php from my knowledge of other languages, too, so don't be afraid to talk technical with me; but not too technical.

推荐答案

关于这个答案有很多评论,所以我发布这个作为答案。

there are so many comments on this answer so I'm posting this as an answer.

让它在我的电脑上工作。

Got it working on my pc.

使用svens代码:


use svens code :

    $images = array( $_GET['color'], $_GET['face'], $_GET['hat'] );

    // Allocate new image
    $img = imagecreatetruecolor(58, 75);
    // Make alpha channels work
    imagealphablending($img, true);
    imagesavealpha($img, true);

    foreach($images as $fn) {
        // Load image
        $cur = imagecreatefrompng($fn);
        imagealphablending($cur, true);
        imagesavealpha($cur, true);

        // Copy over image
        imagecopy($img, $cur, 0, 0, 0, 0, 58, 75);

        // Free memory
        imagedestroy($cur);
    }   

    header('Content-Type: image/png');  // Comment out this line to see PHP errors
    imagepng($img);

?>

我将这样的图像重命名为更容易:

I renamed your images like this so its easier :



微笑:a.png

耳机:b.png

蓝色:c.png


smile : a.png
headset : b.png
blue : c.png

原来问题在于分层。在重命名图像后,将一个放在另一个

后,使用此URL - 它将起作用(在我的电脑上工作)。

after you rename the images, use this url -- it will work(works on my pc).

YOUR_FILE.php?hat = b.png& color = c.png& face = a.png

YOUR_FILE.php?hat=b.png&color=c.png&face=a.png

这仍然会给你一个黑色的背景。我不确定你在服务器上的文件中是否有与上面完全相同的代码 - 因为我在你的链接上玩了图像顺序而没有帮助。尝试在不同的文件上复制粘贴这个完全相同的代码,然后尝试。玩弄订单并查看结果。

This will still give you a black background. I am not sure if you have the exact same code as above in your file on the server - because I played around with the image order on your link and it does not help. Try copy-pasting this exact same code on a different file and then trying. Play around with the order and check the results.

这篇关于如何通过PHP将3个图像合并为1个图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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