在PHP中将一个图像添加到另一个图像的底部 [英] Adding one image at the bottom of another in PHP

查看:152
本文介绍了在PHP中将一个图像添加到另一个图像的底部的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在php中将一个图像添加到另一个图像的底部

I'd like to add one image to the bottom of another in php

我要加载图像:

//load top
$top = @imagecreatefrompng($templateTop);
//load bottom
$bottom = @imagecreatefrompng($templateBottom);

现在,我想将它们添加到一张图片中,并同时显示顶部和底部.

Now I'd like to add them to one picture and display top and bottom together.

我该怎么做?

谢谢!

推荐答案

使用图像复制:

$top_file = 'image1.png';
$bottom_file = 'image2.png';

$top = imagecreatefrompng($top_file);
$bottom = imagecreatefrompng($bottom_file);

// get current width/height
list($top_width, $top_height) = getimagesize($top_file);
list($bottom_width, $bottom_height) = getimagesize($bottom_file);

// compute new width/height
$new_width = ($top_width > $bottom_width) ? $top_width : $bottom_width;
$new_height = $top_height + $bottom_height;

// create new image and merge
$new = imagecreate($new_width, $new_height);
imagecopy($new, $top, 0, 0, 0, 0, $top_width, $top_height);
imagecopy($new, $bottom, 0, $top_height+1, 0, 0, $bottom_width, $bottom_height);

// save to file
imagepng($new, 'merged_image.png');

这篇关于在PHP中将一个图像添加到另一个图像的底部的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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