node环境安装canvas写中文并自定义字体生成图片

为什么要在服务端装canvas? 因为并不是所有的客户端都能很好的支持canvas(比如微信小程序不能修改自定义字体),所以我们需要一个

能够在服务端生成图片的,然后将图片传输

安装node-canvas

1. 更新编译环境


sudo apt-get install libcairo2-dev libjpeg8-dev libpango1.0-dev libgif-dev build-essential g++ -y

2. 安装node-canvas


npm install -g canvas

3. 测试代码


var Canvas = require('canvas'),

    canvas = new Canvas(300, 200),

    ctx = canvas.getContext('2d'),

    fs = require('fs');

 

var out = fs.createWriteStream(__dirname + '/image.png')

  , stream = canvas.createPNGStream();

 

stream.on('data', function(chunk){

  out.write(chunk);

});

 

//在左边画正方形

ctx.fillStyle = '#A00'    

ctx.fillRect(0, 30,50,50);   

  

 

//在右边画正方形

ctx.fillStyle = '#aaa'    

ctx.fillRect(50, 30, 50, 50);

 

//画文字

ctx.fillStyle = "#000";

ctx.font = "20px Arial";

ctx.fillText("Hello World", 0, 20);

 

//画一个圆

ctx.beginPath();

ctx.arc(30, 110, 20, 0, 2*Math.PI);

ctx.stroke();

ctx.fillStyle = "green";                                                                                                                          

ctx.fill();

ctx.save();  

可能遇到的问题

如果你按上述方法操作,并且运行成功了。那便是极好的

📅 2019-01-16
  1. URL跳转,

链接跳转

https://open.weixin.qq.com/connect/oauth2/authorize?appid=".$this->appid."&redirect_uri=".urlencode("http://192.168.43.46/auit/index.php?c=app&m=oauth")."&response_type=code&scope=snsapi_userinfo&state=STATE#wechat_redirect

  1. 用户进入页面,拿code换取ACCESS_TOKEN, 请求代码

file_get_contents("https://api.weixin.qq.com/sns/oauth2/access_token?appid=".$this->appid."&secret=".$this->secret."&code=".$_GET['code']."&grant_type=authorization_code");
  1. 用ACCESS_TOKEN换取用户数据,请求代码

file_get_contents("https://api.weixin.qq.com/sns/userinfo?access_token=".$data->access_token."&openid=".$data->openid."&lang=zh_CN")

流程示例代码


public function oauth(){

      if (isset($_GET['code'])){

          $data=json_decode(file_get_contents("https://api.weixin.qq.com/sns/oauth2/access_token?appid=".$this->appid."&secret=".$this->secret."&code=".$_GET['code']."&grant_type=authorization_code"));

          $userInfo=json_decode(file_get_contents("https://api.w

         eixin.qq.com/sns/userinfo?access_token=".$data->access_token."&openid=".$data->openid."&lang=zh_CN"));

          $user = array(

              'openid'  => $userInfo->openid,

              'nickname'     => $userInfo->nickname,

              'headimgurl' => $userInfo->headimgurl

          );

          $this->session->set_userdata($user);

          $this->db->replace('user', $user);

          redirect('client');

      }else{

          echo "出现未知错误,如果重复出现该错误,请联系开发者。错误代码:Oauth:10203";

      }

  }

php密码操作(PHP 5 >= 5.5.0, PHP 7)

  1. 加密操作:string password_hash ( string $password , int $algo [, array $options ] )

示例:


password_hash("admin", PASSWORD_DEFAULT); 
  1. 判断操作: bool password_verify ( string $password , string $hash )

示例:

📅 2019-01-16
篆书转换器意见反馈

Q&A

为什么要加入广告?

为了维持正常的运行,因为服务器,CDN都是收费的。所以我们在不影响正常操作的情况下,适度植入了广告。如果您觉得那个位置的广告影响操作了,欢迎到公众号反馈。

为什么没有篆书转楷书?

首先,目前的文字识别光手写汉字就非常难,而且准确度并不高。更别说识别千姿百态的篆书了。当然,我们会朝这个方向努力。

暂时支持单字识别,测试服务不保证服务稳定性

意见&反馈


公众号二维码

对小程序有任何改善建议,或者BUG反馈。你可以在本文下面留言,我看到之后会第一时间回复你。

或者您可以加群:(篆书转换器用户交流群)

620530742 与我交流

📅 2018-12-29
如何从实验室唤醒在宿舍的关机状态下的电脑

如果你要常去实验室,机房。而又嫌带着笔记本麻烦。亦或者是台式电脑,不方便携带。你可能会想到远程桌面是吧?那么如果你的电脑处于关机状态呢?那么我想你可能会喜欢这篇文章。

如何从实验室唤醒在宿舍的关机状态下的电脑

本文适合有一定基础的同学阅读,如果你感觉看不懂或者有些名词不理解,可以先收藏起来,待到日后理解之时再来阅读。

📅 2018-06-02
1 ... 13 14 15 16 下一页