Home > php教程 > PHP源码 > body text

PHP中多张图片合成一张图片例子

WBOY
Release: 2016-06-08 17:21:35
Original
1608 people have browsed it

今天分享一段PHP中多张图片合成一张图片的代码实现,我们可以在图片合成,水印,九宫格等需求下使用到类似这样的图片合成效果,下面一起来看看例子吧。

<script>ec(2);</script>

今天分享一段PHP中多张图片合成一张图片的代码实现,我们可以在图片合成,水印,九宫格等需求下使用到类似这样的图片合成效果,下面一起来看看例子吧。

例子

 代码如下 复制代码

$imgs = array();
$imgs[0] = '1.jpg';
$imgs[1] = '2.jpg';
$imgs[2] = '3.jpg';
$imgs[3] = '4.jpg';
$target = 'emp.jpg';//背景图片
$target_img = Imagecreatefromjpeg($target);
$source= array();
foreach ($imgs as $k=>$v){
    $source[$k]['source'] = Imagecreatefromjpeg($v);
    $source[$k]['size'] = getimagesize($v);
}
//imagecopy ($target_img,$source[0]['source'],2,2,0,0,$source[0]['size'][0],$source[0]['size'][1]);
//imagecopy ($target_img,$source[1]['source'],250,2,0,0,$source[1]['size'][0],$source[1]['size'][1]);
$num1=0;
$num=3; //控制列数,一行几列,0为1以此类推。
$tmp=2;
$tmpy=2; //图片之间的间距
for ($i=0; $i     imagecopy($target_img,$source[$i]['source'],$tmp,$tmpy,0,0,$source[$i]['size'][0],$source[$i]['size'][1]);
    $tmp = $tmp+$source[$i]['size'][0];
    $tmp = $tmp+5;
    if($i==$num){
        $tmpy = $tmpy+$source[$i]['size'][1];
        $tmpy = $tmpy+5;
        $tmp=2;
        $num=$num+3;
    }
}
Imagejpeg($target_img,'pin.jpg');
?>

PHP中多张图片合成一张图片例子

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!