Symfony生成二维码的方法,symfony生成
本文实例讲述了Symfony生成二维码的方法。分享给大家供大家参考,具体如下:
现在网上能搜到很多关于使用PHP生成二维码的例子,主要是两种方法:
第一种:google开放api,如下:
$urlToEncode="http://blog.it985.com"; generateQRfromGoogle($urlToEncode); function generateQRfromGoogle($chl, $widhtHeight = '150', $EC_level = 'L', $margin = '0') { $url = urlencode($url); echo '<img src="/static/imghwm/default1.png" data-src="http://chart.apis.google.com/chart?chs='.$widhtHeight.'x'.$widhtHeight.'&cht=qr&chld='.$EC_level.'|'.$margin.'&chl='.$chl.'" class="lazy".$widhtHeight.'x'.$widhtHeight.'&cht=qr&chld='.$EC_level.'|'.$margin.'&chl='.$chl.'" alt="QR code" />'; }
附:API接口地址 https://developers.google.com/chart/infographics/docs/qr_codes
第二种:使用PHP类库 PHP QR CODE
官方地址:http://phpqrcode.sourceforge.net/
下载地址:http://sourceforge.net/projects/phpqrcode/
也可点击此处本站下载。
使用方法:
<?php // include这两个文件之一: /* qrlib.php for full version (also you have to provide all library files form package plus cache dir) OR phpqrcode.php for merged version (only one file, but slower and less accurate code because disabled cache and quicker masking configured) */ // 两句话解释: // 包含qrlib.php的话需要同其它文件放到一起:文件、文件夹。 // phpqrcode.php是合并后版本,只需要包含这个文件,但生成的图片速度慢而且不太准确 include('./phpqrcode/phpqrcode.php'); // 以下给出两种用法: // 创建一个二维码文件 QRcode::png('code data text', 'filename.png'); // creates file // 生成图片到浏览器 QRcode::png('some othertext 1234'); ?>
附官方示例代码地址:http://phpqrcode.sourceforge.net/examples/index.php
当然,还有其他方法生成二维码,这里就不一一介绍了。
下面我们说一下在Symfony下使用EndroidQrCodeBundle生成二维码:
1、使用composer安装
复制代码 代码如下:composer require endroid/qrcode-bundle
2、在kernel中注册
<?php // app/AppKernel.php public function registerBundles() { $bundles = array( // ... new Endroid\Bundle\QrCodeBundle\EndroidQrCodeBundle(), ); }
3、定义访问路由
EndroidQrCodeBundle: resource: "@EndroidQrCodeBundle/Controller/" type: annotation prefix: /qrcode
4、配置 config.xml
endroid_qr_code: size: 100 padding: 10 extension: gif error_correction_level: high foreground_color: { r: 0, g: 0, b: 0, a: 0 } background_color: { r: 255, g: 255, b: 255, a: 0 } #label: "My label" #labelFontSize: 16
5、在twig中使用
普通文本生成方式:
<img src="{{ qrcode_url(message) }}" / alt="Symfony生成二维码的方法,symfony生成" > <img src="{{ qrcode_url(message, extension='png') }}" / alt="Symfony生成二维码的方法,symfony生成" > <img src="{{ qrcode_url(message, size=150) }}" / alt="Symfony生成二维码的方法,symfony生成" >
链接生成方式:
复制代码 代码如下:
本文永久地址:http://blog.it985.com/12340.html
本文出自 IT985博客 ,转载时请注明出处及相应链接。
更多关于PHP相关内容感兴趣的读者可查看本站专题:《PHP图形与图片操作技巧汇总》、《php优秀开发框架总结》、《ThinkPHP入门教程》及《codeigniter入门教程》
希望本文所述对大家基于Symfony框架的PHP程序设计有所帮助。
您可能感兴趣的文章:
- Symfony2安装第三方Bundles实例详解
- Symfony2使用第三方库Upload制作图片上传实例详解
- Symfony2在Nginx下的配置方法图文教程
- Symfony2安装的方法(2种方法)
- Symfony2 session用法实例分析
- Symfony学习十分钟入门经典教程
- PHP的Symfony和CodeIgniter框架的Nginx重写规则配置
- Symfony数据校验方法实例分析
- symfony表单与页面实现技巧
- Symfony页面的基本创建实例详解
- 高性能PHP框架Symfony2经典入门教程
- 如何在symfony中导出为CSV文件中的数据
- Symfony2实现在doctrine中内置数据的方法

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

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

Zend Studio 13.0.1
Powerful PHP integrated development environment

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

WebStorm Mac version
Useful JavaScript development tools
