当前位置: 编程技术>php
php制作中间带自己定义图片二维码的方法
来源: 互联网 发布时间:2014-08-26
本文导语: 1,首先你必须生成二维码具体代码如下: 代码如下: class QRCode{ public $w; public $h; public $s; function __construct($w1,$h1,$s1){ $this->w = $w1; $this->h = $h1; $this->s = $s1; $this->outimgase(); } function qrcode(){ $post_data = array(); $post_data['cht'] = 'qr'; $post_d...
1,首先你必须生成二维码具体代码如下:
class QRCode{
public $w;
public $h;
public $s;
function __construct($w1,$h1,$s1){
$this->w = $w1;
$this->h = $h1;
$this->s = $s1;
$this->outimgase();
}
function qrcode(){
$post_data = array();
$post_data['cht'] = 'qr';
$post_data['chs'] = $this->w."x".$this->h;
$post_data['chl'] = $this->s;
$post_data['choe'] = "UTF-8";
$url = "http://chart.apis.google.com/chart";
$data_Array = array();
foreach($post_data as $key => $value)
{
$data_Array[] = $key.'='.$value;
}
$data = implode("&",$data_Array);
$ch = curl_init();
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POSTFIELDS,$data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec($ch);
curl_close($ch);
return $result;
}
function outimgase(){
echo $this->qrcode();
}
}
header("Content-type:image/png");
$t = new QRCode(300,300,"tianxin");
2,然后通过一个php文件将二维码和你的目的图片画在一起代码如下:
代码如下:
class QRCode{
public $w;
public $h;
public $s;
function __construct($w1,$h1,$s1){
$this->w = $w1;
$this->h = $h1;
$this->s = $s1;
$this->outimgase();
}
function qrcode(){
$post_data = array();
$post_data['cht'] = 'qr';
$post_data['chs'] = $this->w."x".$this->h;
$post_data['chl'] = $this->s;
$post_data['choe'] = "UTF-8";
$url = "http://chart.apis.google.com/chart";
$data_Array = array();
foreach($post_data as $key => $value)
{
$data_Array[] = $key.'='.$value;
}
$data = implode("&",$data_Array);
$ch = curl_init();
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POSTFIELDS,$data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec($ch);
curl_close($ch);
return $result;
}
function outimgase(){
echo $this->qrcode();
}
}
header("Content-type:image/png");
$t = new QRCode(300,300,"tianxin");
2,然后通过一个php文件将二维码和你的目的图片画在一起代码如下: