php生成带有二维码的海报

阅读次数: 6,678

  • A+
所属分类:PHP 语言学习

不多说直接上代码

/* 传递两个图片 生成新的海报图片 */
        /**
         * auther:Jack
         * @param $source_img 海报底图
         * @param $code_png  二维码图片
         * @param $x  海报图上的 X位置
         * @param $y  海报图上的 Y位置
         * @param $width  二维码的宽度
         * @param $path  存放新海报的地址
         * @param $new_name  新海报的名称
         */
		public function create_haibao($source_img,$code_png,$x,$y,$width,$path,$new_name){
                    $source_file = imagecreatefromjpeg($source_img);
                    $source_file_w = imagesx($source_file);
                    $source_file_h = imagesy($source_file);
                    $target_file = imagecreatetruecolor($source_file_w,$source_file_h);//创建一个画布
                    $background_white = imagecolorallocate($target_file,255,255,255);//创建一个白色背景
                    imagefill($target_file,$background_white);//将白色背景填充到 画布里
                    imagecopyresampled($target_file,$source_file,0,0,0,0,$source_file_w,$source_file_h,$source_file_w,$source_file_h);//复制一份原背景图
                    $code_file = imagecreatefrompng($code_png);//png 格式的 二维码资源
                    $width = ($width>0)?$width:imagesx($code_file);//宽度
                    $heigth = $width;//正方形的
                    imagecopyresampled($target_file,$code_file,$x,$y,0,0,$width,$heigth,imagesx($code_file),imagesy($code_file));
                    imagedestroy($code_file);
        
                    imagejpeg($target_file,$path.$new_name);
                    imagedestroy($source_file);
                    imagedestroy($target_file);
        }
  • 我的微信
  • 这是我的微信扫一扫
  • weinxin
  • 我的微信公众号
  • 我的微信公众号扫一扫
  • weinxin

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: