PHP生成条形码
2016-04-15 16:25
531 查看
首先找到强大的开源资料,在barcode官网下载barcodegen.1d-php5.v5.0.1.zip版本,然后解压文件放到你的Apache服务器的根目录下。
参考 http://www.cnblogs.com/ForEvErNoME/archive/2012/04/21/2460944.html
$text = $_GET['code']; require_once('./barcodegen/BCGFontFile.php'); require_once('./barcodegen/BCGColor.php'); require_once('./barcodegen/BCGDrawing.php'); require_once('./barcodegen/BCGcode128.barcode.php'); $font = new BCGFontFile('./barcodegen/font/Arial.ttf', 18); $color_black = new BCGColor(0, 0, 0); $color_white = new BCGColor(255, 255, 255); $drawException = null; try { $code = new BCGcode128(); $code->setScale(2); // Resolution $code->setThickness(30); // Thickness $code->setForegroundColor($color_black); // Color of bars $code->setBackgroundColor($color_white); // Color of spaces $code->setFont($font); // Font (or 0) $code->parse($text); // Text } catch(Exception $exception) { $drawException = $exception; } $drawing = new BCGDrawing('', $color_white); if($drawException) { $drawing->drawException($drawException); } else { $drawing->setBarcode($code); $drawing->draw(); } header('Content-Type: image/png'); header('Content-Disposition: inline; filename="barcode.png"'); $drawing->finish(BCGDrawing::IMG_FORMAT_PNG);
参考 http://www.cnblogs.com/ForEvErNoME/archive/2012/04/21/2460944.html
相关文章推荐
- php pcntl_fork 多进程僵尸进程的问题
- 15个实用的PHP正则表达式
- PHP - 目录、文件操作
- pure-ftp脚本
- 【php趣味】__CLASS__、get_class、get_called_class三兄弟
- php 登录实例演示
- php 登录实例演示
- php 登录实例演示
- php使用php-fpm重启、停止操作命令
- 【PHP趣味】new self和new static的区别
- laravel-v4.0.9
- 类与对象
- PHPMailer使用
- 【php学习】数组操作
- 【转载】PHP运行模式的深入理解
- php反射例子
- PHPthinking在线编程工具终极版
- Yaf学习笔记1--Windows环境下安装Yaf
- php设计模式之单例模式实例(设计mysqli连接数据的数据处理类)
- laravel 一点操作