网站服务器是 linux(查了些资料有个 windows 的实现方法,所以强调下)
在微信中用,说下最终实现目标吧。
就是微信回复关键字,生成有用户昵称和头像的二维码,现在遇到的问题是: php 写了个页面,可以获取微信用户头像和昵称,但是在想怎么用 php 获取这个网页的截图,然后返回给用户。
微信回复图片的功能已经开发好了,
1
chenwl 2016-01-04 15:53:49 +08:00
截图的可以用 phantomjs 执行脚本 到这个网页截图保存
|
2
Kokororin 2016-01-04 15:54:41 +08:00
cutycapt
|
3
nigelvon 2016-01-04 16:02:00 +08:00
不如直接用 gd 画一个,听起来不是什么特别复杂的网页。非要做网页截图可以用 phantomJS
|
4
6IbA2bj5ip3tK49j 2016-01-04 16:03:04 +08:00
感觉你的需求没必要截图啊,不如说说你要截图干嘛。
|
6
naomhan 2016-01-04 16:11:12 +08:00
感觉你是要做生成名片那种功能,还是画出来比较靠谱
|
8
yanwen 2016-01-04 16:13:02 +08:00
之前记得站内有人发过出来。。好久之前了 不记得了。。搜索看看吧。
|
9
jarlyyn 2016-01-04 16:13:36 +08:00
wildimage/gd 直接画?
画背景图,画前景图,画文字 |
10
cond0r 2016-01-04 16:14:34 +08:00
设置好图片模版,然后获取头像的数据,写入,然后 gd 生生二维码和昵称 拼接一下就好了,也不用截图
|
11
6IbA2bj5ip3tK49j 2016-01-04 16:15:46 +08:00
|
12
l1905 2016-01-04 16:27:07 +08:00
可以考虑 html=>pdf=>image , 开销可能会比较大
|
14
chaegumi 2016-01-04 17:35:54 +08:00
用 phantomjs ,我就是这样做的。 http://phantomjs.org/screen-capture.html , php 调用命令的方式
|
15
wd0g 2016-01-04 18:06:18 +08:00
php 怕是不行,html 是由浏览器来格式化的
你 php 只能获取到 html |
16
dapang1221 2016-01-04 18:16:39 +08:00 via Android
不用截图。直接通过 gd 库,把所需要的东西叠加在一张模板图片上就行
|
17
Tink 2016-01-04 18:18:07 +08:00 via iPhone
模版是统一好的嘛?是的话就提取昵称和头像然后填到模版里
|
18
Kokororin 2016-01-04 18:37:22 +08:00
@ningyuqiao456 既然只要昵称和头像,直接用 gd 生成即可
|
19
imnpc 2016-01-04 20:18:08 +08:00
当然是 GD 生成啊
[code] $affiliate = unserialize($GLOBALS['_CFG']['affiliate']); $level_register_up = (float)$affiliate['config']['level_register_up']; $rank_points = $GLOBALS['db']->getOne("SELECT rank_points FROM " . $GLOBALS['ecs']-> table('users') . "where user_id=" . $user_id); if ($rank_points < $level_register_up) { $msgType = "text"; $contentStr = "您还不是分销商,暂时不能获取推广二维码."; $resultStr = sprintf($textTpl, $fromUsername, $toUsername, $time, $msgType, $contentStr); $this->universal($fromUsername, $base_url); $this->insert_wmessage($db, $fromUsername, $contentStr, $time, $belong); echo $resultStr; exit; } $ArticleCount = 1; $scene_id = $user_id; $affiliate = $user_id; $gourl = $base_url . 'wechat/egg/index1.php?scene_id=' . $scene_id; $type = 'tj'; $qr_path = $db->getOne("SELECT `qr_path` FROM `wxch_qr` WHERE `scene_id`='$scene_id'"); $user_name = $db->getOne("SELECT `user_name` FROM `ecs_users` WHERE `user_id`='$scene_id'"); $scene = $user_name; $qr_path = $db->getOne("SELECT `qr_path` FROM `wxch_qr_tianxin100` WHERE `scene_id`='$scene_id'"); /**/ if (!empty($qr_path)) { $surl = $qr_path; $data = dirname(__FILE__) . "/qrcode/" . $surl; } else { $action_name = "QR_LIMIT_SCENE"; $json_arr = array('action_name' => $action_name, 'action_info' => array('scene' => array('scene_id' => $scene_id))); $data = json_encode($json_arr); $this->access_token($db); $ret = $db->getRow("SELECT `access_token` FROM `wxch_config`"); $access_token = $ret['access_token']; if (strlen($access_token) >= 64) { $url = 'https://api.weixin.qq.com/cgi-bin/qrcode/create?access_token=' . $access_token; $res_json = $this->curl_grab_page($url, $data); $json = json_decode($res_json); } $ticket = $json->ticket; if ($ticket) { $ticket_url = urlencode($ticket); $ticket_url = 'https://mp.weixin.qq.com/cgi-bin/showqrcode?ticket=' . $ticket_url; $imageinfo = $this->downloadimageformweixin($ticket_url); $time = time(); $url = $_SERVER['HTTP_HOST']; $path = '../images/qrcode/' . $time . '.jpg'; $surl = "http://" . $url . '/images/qrcode/' . $time . '.jpg'; $local_file = fopen($path, 'a'); $h_path = '../images/qrcode/head/' . $time . '.jpg'; $h_local_file = fopen($h_path, 'a'); $headimgurl = $db->getOne("SELECT `headimgurl` FROM `wxch_user` WHERE `wxid`='$fromUsername'"); $h_imageinfo = $this->downloadimageformweixin($headimgurl); if (false !== $local_file) { if (false !== fwrite($local_file, $imageinfo) && false !== fwrite($h_local_file, $h_imageinfo)) { fclose($local_file); //将生成的二维码图片的地址放到数据库中 $insert_sql = "INSERT INTO `wxch_qr` (`type`,`action_name`,`ticket`, `scene_id`, `scene` ,`qr_path`,`function`,`affiliate`,`endtime`,`dateline`) VALUES ('$type','$action_name', '$ticket',$scene_id, '$scene' ,'$surl','$function','$affiliate','$endtime','$dateline')"; $db->query($insert_sql); } } } $imgsrc = "../images/qrcode/" . $time . ".jpg"; $h_imgsrc = "../images/qrcode/head/" . $time . ".jpg"; $width = 230; $height = 230; $time = time(); $name = $this->resizejpg($imgsrc, $width, $height, $time); $imgs = $name; //处理头像 $width = 100; $height = 100; $h_time = $time . "_1"; $h_name = $this->resizejpg($h_imgsrc, $width, $height, $h_time); $h_imgs = $h_name; $target = '../qrcode/tianxin100.jpg'; //背景图片 $target_img = Imagecreatefromjpeg($target); $source = Imagecreatefromjpeg($imgs); $h_source = Imagecreatefromjpeg($h_imgs); imagecopy($target_img, $source, 155, 462, 0, 0, 230, 230); imagecopy($target_img, $h_source, 60, 28, 0, 0, 100, 100); $fontfile = "simsun.ttf"; #水印文字 $nickname = $db->getOne("SELECT `nickname` FROM `wxch_user` WHERE `wxid`='$fromUsername'"); #打水印 $textcolor = imagecolorallocate($target_img, 0, 0, 255); imagettftext($target_img, 18, 0, 268, 59, $textcolor, $fontfile, $nickname); Imagejpeg($target_img, 'qrcode/' . $time . '.jpg'); $data = dirname(__FILE__) . "/qrcode/" . $time . ".jpg"; $s_data = $time . ".jpg"; $insert_sql = "INSERT INTO `wxch_qr_tianxin100` (`qr_path`,`scene`,`scene_id`, `nickname`) VALUES ('$s_data','$scene', '$scene_id','$nickname')"; $db->query($insert_sql); } $filedata = array("media" => "@" . $data); $this->access_token($db); $ret = $db->getRow("SELECT `access_token` FROM `wxch_config`"); $access_token = $ret['access_token']; if (strlen($access_token) >= 64) { $url = 'http://file.api.weixin.qq.com/cgi-bin/media/upload?access_token=' . $access_token . '&type=image'; $res_json = $this->https_request($url, $filedata); $json = json_decode($res_json); } $msgType = "image"; $iipp = $_SERVER["REMOTE_ADDR"]; $phone_state = $_SERVER['HTTP_USER_AGENT']; $contentStr = $json->media_id; $resultStr = sprintf($imageTpl, $fromUsername, $toUsername, $time, $msgType, $contentStr); $this->insert_wmessage($db, $fromUsername, $contentStr, $time, $belong); $this->universal($fromUsername, $base_url); echo $resultStr; exit; } [/code] |
21
uglyer 2016-01-04 23:23:15 +08:00 via iPhone
参考水印合成的吧,最好理解了。
|
22
mathoidliu 2016-01-05 11:30:57 +08:00
我靠, 一看头像以为是发神 @Aufree
|
23
mathoidliu 2016-01-05 11:32:46 +08:00
是 @PaulKing
|
24
mathoidliu 2016-01-05 11:33:17 +08:00
这么牛逼的头像....
|