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."张证件照。"; } } ?>
声明:该文观点仅代表作者本人,牛骨文系教育信息发布平台,牛骨文仅提供信息存储空间服务。
- 上一篇: PHP 图片合成
- 下一篇: Laravel5中通过SimpleQrCode扩展包生成二维码实例