php 绘图合并两张jpg图片 并在图片上写字

两张jpg图合并,并且中间小图进行压缩。 并在图片上写字(注:"simhei.ttf" 放在项目根目录下 或  ./)


<?php 

function create_certificates(){

          $matchid = $_SESSION['adminmatch'];
          //本赛事所有人员参报信息        
        $arrAllplayer = $this->Search_model->getallplayer($matchid);     
        // var_dump($arrAllplayer);
        // die();    
        //取得组别,用于遍历$arrAllplayer进行统计分类
        $EventType = $this->Search_model->getEvntType($matchid);    
        $NewarrTeam = $this->Search_model->constructArrplayer($arrAllplayer);//重构数组




        //队员证件,合并拼图
        function mergerImg($imgs,$realname,$groupname,$typena,$userid) {        
    
            //得到图片的宽高 
            list($max_width, $max_height) = getimagesize($imgs['dst']);
            if($max_width>$max_height ){
                $newwidth = $max_width / ( $max_width/200) ;
                $newheight = $max_height / ($max_width/200 );
            }else{
                $newwidth = $max_width / ( $max_height/250) ;
                $newheight = $max_height / ($max_height/250 );
            }
            
            
            $dests = imagecreatetruecolor($max_width, $max_height);
             
            $dst_im = imagecreatefromjpeg($imgs['dst']);
            //$im = @imagecreatefromjpeg($imgname);
            
            imagecopy($dests,$dst_im,0,0,0,0,$max_width,$max_height);
            imagedestroy($dst_im);
             
            $src_im = imagecreatefromjpeg($imgs['src']);
            $src_info = getimagesize($imgs['src']);
            //imagecopy($dests,$src_im,120,$max_height/2,0,0,$src_info[0],$src_info[1]);
            imagecopyresized($dests,$src_im,120,450,0,0,$newwidth, $newheight,$src_info[0],$src_info[1]);
            imagedestroy($src_im);
             

            //建立一幅100*30的图像
            //    $image = imagecreatetruecolor(2000,100);

            //设置背景颜色
            // $bgcolor = imagecolorallocate($image,0,0,0);

            //设置字体颜色
            $textcolor = imagecolorallocate($dests,0,0,0);
            
            //$black = ImageColorAllocate($dests, 0,0,0);
            $white = ImageColorAllocate($dests, 0,0,0);
            ImageTTFText($dests, 20, 0, 450, 550, $white, "./simhei.ttf", $realname);
            ImageTTFText($dests, 20, 0, 450, 620, $white, "./simhei.ttf", $groupname);
            ImageTTFText($dests, 20, 0, 450, 690, $white, "./simhei.ttf", $typena);
            
            //把字符串写在图像左上角
            //imagestring($dests,20,450,540,"$realname",$textcolor);
            //imagestring($dests,20,450,620,"Hello world!",$textcolor);
            //imagestring($dests,20,450,690,"Hello world!",$textcolor);

            header("Content-type: image/jpeg");
            imagejpeg($dests,'../download/img/'.$userid.'.jpg');
            //imagedestroy($dests); 
            
            imagejpeg($dests);
        }



        function get_extension($file_name)
        {
            $extend =explode("." , $file_name);
            return end($extend);
        }    

        if($NewarrTeam){
            
            $intrecord = 1;
            $m = 0;
            foreach($NewarrTeam as $key => $value){

                //echo "正在生成,生成证件时间大概2-3分钟,请稍等.........";

                //echo $value['realname'], $value['userid'], ".jpg";

                $n = $value['status'];
                $arrarrOrderStatus = $this->Common_model->getStatusArry();                                                
                $playerStatus[] = $arrarrOrderStatus[$n];


                //'3' 已经付款完成的所有队员 
                if($n=='3'){

                    if(get_extension($value['userpic'])!="jpg" && get_extension($value['userpic'])!="JPG"){
                        $value['userpic'] = 'card';
                        
                    }



                    $m = $m + 1;

                          $imgs = array(
                                'dst' => base_url().'../upload/image/basemap.jpg',
                                'src' => base_url().'../upload/image/'.$value['userpic']//'http://www.wangshangyou.com/content/uploadfile/201312/72691386051117.png'
                        );
                        mergerImg($imgs,$value['realname'],$value['groupName'],$value['typename'],$value['userid']);
                        
                   
                    // if($m==1){
                    //     break;
                    // }    
                }
                
            }
            die();
            echo "正在完成,共生成".$m."张证件照。";


      }
  }

?>


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

蜗牛慢慢向上爬

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值