飞狐爷

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理
 1 require('../includes/init.php');
 2 require(ROOT_PATH . '/includes/cls_weixin.php');
 3 require(ROOT_PATH . '/includes/cls_image.php');
 4 //获得二维码图片
 5 function downloadimagefromweixin($url){
 6     $ch = curl_init($url);
 7     curl_setopt($ch, CURLOPT_HEADER,0);
 8     curl_setopt($ch, CURLOPT_NOBODY,0);
 9     curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,FALSE);
10     curl_setopt($ch, CURLOPT_SSL_VERIFYHOST,FALSE);
11     curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
12     $package = curl_exec($ch);
13     $httpinfo = curl_getinfo($ch);
14     curl_close($ch);
15     return array_merge(array('body'=>$package),array('header'=>$httpinfo));
16 }
17 $img = new cls_image();
18 
19 $filename = $img->random_filename().'.jpg'; //新文件名字
20 $fileRedictory = './images/';
21 if(!file_exists($fileRedictory)){
22     mkdir ($fileRedictory);//创建二维码存放文件夹
23 }
24 
25 
26 $qrcode = new qrcode('450');
27 $img_url = $qrcode->qr_scene(); // 需要抓取的远程图片
28 $imageinfo = downloadimagefromweixin($img_url);
29 $local_file = fopen('./images/'.$filename, 'w');
30 //如果没有打开文件,进行写入操作
31 if(false !==$local_file){
32     if(false !==fwrite($local_file, $imageinfo['body'])){
33         fclose($local_file);
34     }
35 }
36 $thumbImgUrl = $img->make_thumb('images/'.$filename, '100', '100', 'thumbimg/');
37 $tuiguangImg = $img->add_watermark('./aaa.jpg', 'thumbimg/'.$img->random_filename().'.jpg', $thumbImgUrl, 6, 100);
38 if($thumbImgUrl){
39     unlink($fileRedictory . $filename);
40     if($tuiguangImg) unlink($thumbImgUrl);
41 }
42 echo '<img src="/'.$tuiguangImg.'"><br>';
43 echo '二维码保存成功<br>';

 

posted on 2017-09-29 18:59  飞狐爷  阅读(1347)  评论(0编辑  收藏  举报