实例结构:

1. index.html

<!DOCTYPE html>
<html>
<head>
<title>Test with embedded image</title>
</head>
<body>
  <img src="buildcode.php?text=DJ1307100009&type=BCGcode39" alt="barcode" />
</body>
</html>

  

2. buildcode.php

<?php
// Including all required classes
require_once('class/BCGFontFile.php');
require_once('class/BCGColor.php');
require_once('class/BCGDrawing.php');

// Including the barcode technology
$barcode_name = isset($_REQUEST['type']) ? $_REQUEST['type'] : 'BCGcode39' ;
require_once('class/'.$barcode_name.'.barcode.php');

// Don't forget to sanitize user inputs
$text = isset($_REQUEST['text']) ? $_REQUEST['text'] : 'HELLO';

// Loading Font
$font = new BCGFontFile('./class/font/Arial.ttf', 18);

// The arguments are R, G, B for color.
$color_black = new BCGColor(0, 0, 0);
$color_white = new BCGColor(255, 255, 255);

$drawException = null;
try {
	$code = new $barcode_name();
	$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;
}

/* Here is the list of the arguments
1 - Filename (empty : display on screen)
2 - Background color */
$drawing = new BCGDrawing('', $color_white);
if($drawException) {
	$drawing->drawException($drawException);
} else {
	$drawing->setBarcode($code);
	$drawing->draw();
}

// Header that says it is an image (remove it if you save the barcode to a file)
header('Content-Type: image/png');
header('Content-Disposition: inline; filename="barcode.png"');

// Draw (or save) the image into PNG format.
$drawing->finish(BCGDrawing::IMG_FORMAT_PNG);
?>

  

3. barcode 类库下载地址: ~

效果:

;

php生成条形码: barcodegen的更多相关文章

  1. PHP5生成条形码器

    前阵子在做一个商家优惠券的功能,需要用到条形码,于是将资料重新整理下. 1.什么是条形码? 百度百科定义:条形码(barcode)是将宽度不等的多个黑条和空白,按照一定的编码规则排列,用以表达一组信息 ...

  2. PHP生成条形码

    前阵子在做一个商家优惠券的功能,需要用到条形码,于是将资料重新整理下. 1.什么是条形码? 百度百科定义:条形码(barcode)是将宽度不等的多个黑条和空白,按照一定的编码规则排列,用以表达一组信息 ...

  3. 【PHP】php 生成条形码

    1.什么是条形码? 百度百科定义:条形码(barcode)是将宽度不等的多个黑条和空白,按照一定的编码规则排列,用以表达一组信息的图形标识符.常见的条形码是由反射率相差很大的黑条(简称条)和白条(简称 ...

  4. Excel批量生成条形码

    项目要求需要将信息做成条形码的形式,以便通过手持设备直接查看信息,因本次项目信息为固定信息,不需随机生成,故采用本方法: 代码随机生成二维码暂时没有接触,后续有时间会研究 步骤: 1.新建 Excel ...

  5. php(tp5)生成条形码

    因为公司业务需要,研究了一下条形码 1.下载barcodegen扩展包 官网地址:https://www.barcodebakery.com 2.下载完后解压至 extend 文件夹里面,然后复制以下 ...

  6. C# 在Word文档中生成条形码

    C# 在Word文档中生成条形码 简介 条形码是由多个不同的空白和黑条按照一定的顺序组成,用于表示各种信息如产品名称.制造商.类别.价格等.目前,条形码在我们的日常生活中有着很广泛的应用,不管是在图书 ...

  7. 使用html2canvas实现批量生成条形码

    /*前台代码*/ <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Generat ...

  8. JAVA生成条形码

    1.下载生成条形码所需要的jar包barcode4j.jar: 2.java生成条形码代码 import java.awt.image.BufferedImage;import java.io.Fil ...

  9. C# 生成条形码

    原文地址:http://www.cnblogs.com/xcsn/p/4514759.html 引用BarcodeLib.dll(百度云中有)生成条形 protected void Button2_C ...

随机推荐

  1. 2017.3.31 spring mvc教程(一)核心类与接口

    学习的博客:http://elf8848.iteye.com/blog/875830/ 我项目中所用的版本:4.2.0.博客的时间比较早,11年的,学习的是Spring3 MVC.不知道版本上有没有变 ...

  2. 如何看一个VC工程具体是什么工程?

    VC6等可以创建MFC, Win32等工程,拿到一个工程,怎么判断是什么工程呢? VC6全文检索看看有没有theApp 如果有一般就是MFC的 (VS?)看看工程设置,入口点函数写的是什么,/subs ...

  3. RxJava操作符总结之过滤

    RxJava操作符总结之过滤 jsut() just(T t1, T t2, T t3 ....) ,just能够传入多个同样类型的參数,并将当前參数一个接着一个的发送. Observable.jus ...

  4. Android学习(六) 文本框边框

    BorderTextViews.java package xiaosi.BorderTextView; import android.content.Context; import android.g ...

  5. nginx的buffered to a temporary警告

    nginx日志报a client request body is buffered to a temporary file 这个意思是客户全请求的文件超过了nginx的缓存区大小,nginx将内容写入 ...

  6. vue 的 起手式

    代码: vue.js // vue 起手势 (function(root,factory) { root.Vue = factory(); })(this,function(){ // 设置基础的默认 ...

  7. HDU 3732 Ahui Writes Word(多重背包)

    HDU 3732 Ahui Writes Word(多重背包) http://acm.hdu.edu.cn/showproblem.php? pid=3732 题意: 初始有N个物品, 每一个物品有c ...

  8. cisco 为每个单独的人员设置不同的用户名和密码

    cisco 为每个单独的人员设置不同的用户名和密码 2010-12-15 17:00:16 分类: 系统运维 Router1#configure terminalEnter configuration ...

  9. chrome浏览器提取网页视频

    http://blog.csdn.net/pipisorry/article/details/37728839 在我们平时上网看视频听音乐时都会产生缓存,可是我们非常难通过一些软件把当中的视频和音乐文 ...

  10. asp.net core mvc视频A:笔记3-3.Model与强类型视图

    创建项目,添加TestController 定义一个类(Model),并赋值 建立视图页面 注意:Model是一个特定的对象,取决于传递过来的参数 运行结果 到现在为止,依然没有改变动态类型,需要转换 ...