您好,欢迎访问一九零五行业门户网

php实现中间带自定义图片的二维码

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文件将二维码和你的目的图片画在一起。
$imageinfo[0], height => $imageinfo[1], type => $imagetype, size => $imagesize, mime => $imageinfo['mime'] ); return $info; } else { return false; } } function thumb($image, $thumbname, $type='', $maxwidth=200, $maxheight=50, $interlace=true) { // 获取原图信息 $info = getimageinfo($image); if ($info !== false) { $srcwidth = $info['width']; $srcheight = $info['height']; $type = empty($type) ? $info['type'] : $type; $type = strtolower($type); $interlace = $interlace ? 1 : 0; unset($info); $scale = min($maxwidth / $srcwidth, $maxheight / $srcheight); // 计算缩放比例 if ($scale >= 1) { // 超过原图大小不再缩略 $width = $srcwidth; $height = $srcheight; } else { // 缩略图尺寸 $width = (int) ($srcwidth * $scale); $height = (int) ($srcheight * $scale); } // 载入原图 $createfun = 'imagecreatefrom' . ($type == 'jpg' ? 'jpeg' : $type); $srcimg = $createfun($image); //创建缩略图 if ($type != 'gif' && function_exists('imagecreatetruecolor')) $thumbimg = imagecreatetruecolor($width, $height); else $thumbimg = imagecreate($width, $height); // 复制图片 if (function_exists(imagecopyresampled)) imagecopyresampled($thumbimg, $srcimg, 0, 0, 0, 0, $width, $height, $srcwidth, $srcheight); else imagecopyresized($thumbimg, $srcimg, 0, 0, 0, 0, $width, $height, $srcwidth, $srcheight); if ('gif' == $type || 'png' == $type) { //imagealphablending($thumbimg, false);//取消默认的混色模式 //imagesavealpha($thumbimg,true);//设定保存完整的 alpha 通道信息 $background_color = imagecolorallocate($thumbimg, 0, 255, 0); // 指派一个绿色 imagecolortransparent($thumbimg, $background_color); // 设置为透明色,若注释掉该行则输出绿色的图 } // 对jpeg图形设置隔行扫描 if ('jpg' == $type || 'jpeg' == $type) imageinterlace($thumbimg, $interlace);// 生成图片
$imagefun = 'image' . ($type == 'jpg' ? 'jpeg' : $type); $imagefun($thumbimg, $thumbname); imagedestroy($thumbimg); imagedestroy($srcimg); return $thumbname; } return false; } function water($source, $thumb, $savename=, $alpha=100){ //检查文件是否存在 if (!file_exists($source) || !file_exists($thumb)) return false; //图片信息 $sinfo = getimageinfo($source); $water = thumb($thumb,wy.jpg,jpg,$sinfo[width]/4,$sinfo[height]/4); $winfo = getimageinfo($water); //如果图片小于水印图片,不生成图片 if ($sinfo[width] return false; //建立图像 $screatefun = imagecreatefrom . $sinfo['type']; $simage = $screatefun($source); $wcreatefun = imagecreatefrom . $winfo['type']; $wimage = $wcreatefun($water); //设定图像的混色模式 imagealphablending($wimage, true); //图像位置,默认为右下角右对齐 // $posy = $sinfo[height] - $winfo[height]; // $posx = $sinfo[width] - $winfo[width]; $posy = ($sinfo[height] - $winfo[height])/2; $posx = ($sinfo[width] - $winfo[width])/2; //生成混合图像 imagecopymerge($simage, $wimage, $posx, $posy, 0, 0, $winfo['width'], $winfo['height'], $alpha); //输出图像 $imagefun = 'image' . $sinfo['type']; //如果没有给出保存文件名,默认为原图像名 if (!$savename) { $savename = $source; @unlink($source); } //保存图像 $imagefun($simage, $savename); imagedestroy($simage); } water($source,$water);
复制代码
在上面的代码中用3个函数 grabimage()函数是将生成二维码的文件转化成图片 接下来的函数就是处理图片的缩放 将目的图片添加到二位上。
3,在来一个入口文件index.html 代码如下:
中间可以自己定义图片的二维码生成器_bbs.it-home.org 中间可以自己定义图片的二维码生成器 二维码要生的内容:
希望能添加自己的图片地址:
复制代码
其它类似信息

推荐信息