码迷,mamicode.com
首页 > Web开发 > 详细

PHP将多张小图拼接成一张大图

时间:2016-10-28 20:15:34      阅读:277      评论:0      收藏:0      [点我收藏+]

标签:type   http   ges   之间   背景图片   charset   jpeg   get   for   

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<?php
$imgs = array();
$imgs[0] = ‘imgs/1.jpg‘;
$imgs[1] = ‘imgs/2.jpg‘;
$imgs[2] = ‘imgs/3.jpg‘;
$imgs[3] = ‘imgs/4.jpg‘;
$imgs[4] = ‘imgs/5.jpg‘;
$imgs[5] = ‘imgs/6.jpg‘;
$imgs[6] = ‘imgs/7.jpg‘;
$imgs[7] = ‘imgs/8.jpg‘;
$imgs[8] = ‘imgs/9.jpg‘;
$target  = ‘bg.jpg‘; //背景图片
  
$target_img = Imagecreatefromjpeg($target);
  
$source = array();
  
foreach ($imgs as $k => $v) {
    $source[$k][‘source‘] = Imagecreatefromjpeg($v);
    $source[$k][‘size‘] = getimagesize($v);
}

/*echo "<pre>";
print_r($source);
echo "</pre>";*/

//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  = 2;
$tmp  = 0;
$tmpy = 0; //图片之间的间距
for ($i = 0; $i < 10; $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 + 0;
    if ($i == $num) {
        $tmpy = $tmpy + $source[$i][‘size‘][1];
       // $tmpy = $tmpy + 0;
        $tmp  = 0;
        $num  = $num + 3;
    }
}
Imagejpeg($target_img, ‘pin.jpg‘);
  
?>
<img src="pin.jpg">

技术分享

技术分享

 

PHP将多张小图拼接成一张大图

标签:type   http   ges   之间   背景图片   charset   jpeg   get   for   

原文地址:http://www.cnblogs.com/renxing123/p/6008904.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!