利用google api生成二维码名片例子
二维条码/二维码可以分为堆叠式/行排式二维条码和矩阵式二维条码,堆叠式/行排式二维条码形态上是由多行短截的一维条码堆叠而成,矩阵式二维条码以矩阵的形式组成,在矩阵相应元素位置上用"点"表示二进制"1",用"空"表示二进制"0","点"和"空"的排列组成代码.
堆叠式/行排式二维条码,如,Code 16K、Code 49、PDF417等.
矩阵式二维码,最流行莫过于QR CODE.
矩阵式二维码存储的数据量更大,可以包含数字、字符,及中文文本等混合内容,有一定的容错性(在部分损坏以后可以正常读取),空间利用率高等.
PHP实例代码如下:
<?php $vname = 'test'; $vtel = '13800000000'; generateQRfromGoogle($vname, $vtel); function generateQRfromGoogle($vname, $vtel, $widhtHeight = '150', $EC_level = 'L', $margin = '0') { if ($vname && $vtel) { $chl = "BEGIN:VCARDnVERSION:3.0" . //vcard头信息 "nFN:$vname" . "nTEL:$vtel" . "nEND:VCARD"; //vcard尾信息 echo '<img src="/static/imghw/default1.png" data-src="http://chart.apis.google.com/chart?chs=' . $widhtHeight . 'x' . $widhtHeight . '&cht=qr&chld=' . $EC_level . '|' . $margin . '&chl=' . urlencode($chl) . '" class="lazy" alt="QR code" widhtHeight="' . $size . '" widhtHeight="' . $size . '"/>'; } } ?>
php生成网址二维码,代码如下:
<?php $url = "http://www.google.com.hk"; generateQRfromGoogle($url); function generateQRfromGoogle($chl, $widhtHeight = '150', $EC_level = 'L', $margin = '0') { echo '<img src="/static/imghw/default1.png" data-src="http://chart.apis.google.com/chart?chs=' . $widhtHeight . 'x' . $widhtHeight . '&cht=qr&chld=' . $EC_level . '|' . $margin . '&chl=' . urlencode($chl) . '" class="lazy" alt="QR code" widhtHeight="' . $size . '" widhtHeight="' . $size . '"/>'; } ?>
//例子代码如下:
<?php /* * php 生成二维码名片 * api Google * google api 二维码生成【QRcode可以存储最多4296个字母数字类型的任意文本,具体可以查看二维码数据格式】 * @param string $chl 二维码包含的信息,可以是数字、字符、二进制信息、汉字。不能混合数据类型,数据必须经过UTF-8 URL-encoded.如果需要传递的信息超过2K个字节,请使用POST方式 * @param int $widhtHeight 生成二维码的尺寸设置 * @param string $EC_level 可选纠错级别,QR码支持四个等级纠错,用来恢复丢失的、读错的、模糊的、数据。 * L-默认:可以识别已损失的7%的数据 * M-可以识别已损失15%的数据 * Q-可以识别已损失25%的数据 * H-可以识别已损失30%的数据 * @param int $margin 生成的二维码离图片边框的距离 * 二维码名片的格式---vcard * 格式参考如下: BEGIN:VCARD VERSION:3.0 FN:用户名 TEL;CELL;VOICE:0571-00000000 TEL;WORK;VOICE:0571-00000000 TEL;WORK;FAX:0571-00000000 EMAIL;PREF;INTERNET:361way URL:http://www.111cn.net orG:361way运维之路 ROLE:研发部 TITLE:CTO ADR;WORK;POSTAL:杭州市西湖区XXX号;310000 REV:2014-2-26T08:30:02Z END:VCARD 如果你想更详细的定制所需要的格式,则需要详细的了解vcard的格式标准。 */ $vcard = array( 'vname' => '用户名', 'vtel' => '13800000000', 'vemail' => 'aaaaa@163.com', 'vaddress' => '杭州市西湖区', ); generateQRfromGoogle($vcard);
function generateQRfromGoogle($vcard, $widhtHeight = '150', $EC_level = 'L', $margin = '0') {
if ($vcard) {
$chl = "BEGIN:VCARDnVERSION:3.0" . //vcard头信息
"nFN:" . $vcard['vname'] . "nTEL:" . $vcard['vtel'] . "nEMAIL:" . $vcard['vemail'] . "nADR:" . $vcard['vaddress'] . "nEND:VCARD"; //vcard尾信息
echo '';
}
}
?>
如果想实现中间有logo的效果,需要通过另外一个logo小图进行拼接即可,这里只提供一种实现方法,也可以通过QRcode的方式进行生成.
vcode的标准信息可以参看维基百科.
注:有些生成的图片经扫描没有的数据的原因是编码导致的,该问题在windows下较常见,由于很多编辑器默认提供的是ANSI编码,更改成utf8就OK了.
本文地址:
转载随意,但请附上文章地址:-)

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Currently, four new Pixel smartphones are anticipated to land this autumn. To recap, the series is rumoured to feature thePixel 9 and Pixel 9 Pro at launch. However, the Pixel 9 Pro will be a rival to the iPhone 16 Pro rather than a Pixel 8 Pro (curr

Google AI has started to provide developers with access to extended context windows and cost-saving features, starting with the Gemini 1.5 Pro large language model (LLM). Previously available through a waitlist, the full 2 million token context windo

Google's AI assistant, Gemini, is set to become even more capable, if the APK teardown of the latest update (v15.29.34.29 beta) is to be considered. The tech behemoth's new AI assistant could reportedly get several new extensions. These extensions wi

Google recently responded to the performance concerns about the Tensor G4 of the Pixel 9 line. The company said that the SoC wasn't designed to beat benchmarks. Instead, the team focused on making it perform well in the areas where Google wants the c

Google has introduced DisplayPort Alternate Mode with the Pixel 8 series, and it's present on the newly launched Pixel 9 lineup. While it's mainly there to let you mirror the smartphone display with a connected screen, you can also use it for desktop

The Pixel 9 series is almost here, having been scheduled for an August 13 release. Based on recent rumours, the Pixel 9, Pixel 9 Pro and Pixel 9 Pro XL will mirror the Pixel 8 and Pixel 8 Pro (curr. $749 on Amazon) by starting with 128 GB of storage.

A few months have passed since Android Authority demonstrated a new Android desktop mode that Google had hidden away within Android 14 QPR3 Beta 2.1. Arriving hot on the heels of Google adding DisplayPort Alt Mode support for the Pixel 8 and Pixel 8

Google's AI Test Kitchen, which includes a suite of AI design tools for users to play with, has now opened up to users in well over 100 countries worldwide. This move marks the first time that many around the world will be able to use Imagen 3, Googl
