Home php教程 php手册 PHP5生成条形码的简单实例

PHP5生成条形码的简单实例

Jun 13, 2016 am 11:03 AM
php5 and Example support yes barcode Version generate use of Simple software

该软件支持PHP4和PHP5两个版本,本文中使用的是PHP5的版本。在使用前注意要将PHP的GD模块开启。在Windows中为php_gd2.dll,Linux中为gd.so。将压缩文件解压到Apache,执行http://localhost/barcode/index.php。PHP5生成条形码见下图:

1. Type:选择条形码类型

2. Output:输出的图片格式

3. Thickness:条形码高度

4. Resolution:条形码大小

5. Font:条形码下方的文字大小,也可不显示文字

6. Text:条形码打印的内容

498)this.width=498;' onmousewheel = 'javascript:return big(this)' alt=条码效果 src="http://www.bkjia.com/uploadfile/2013/0904/20130904094617982.jpg" width=615 height=557>

当然,这个PHP5生成条形码程序只是将文字生成为条形码,但使用时不能灵活将其嵌入其他PHP程序,我将压缩包里面的test.php做了一些调整,使其能灵活的用于其他程序。运行时只需将条码类型和文字传给test.php即可,例如:
http://localhost/barcode/test.php?codebar=BCGcode39&text=20090729

或运行 http://localhost/barcode/mytest.php

mytest.php代码:

<span style="COLOR: #0000ff"><pre class="brush:php;toolbar:false"><ol class="dp-xml"><li class="alt"><span><strong><font color="#006699"><span class="tag"><span class="tag-name">img</span></span></font></strong><span><font color="#000000"> </font></span><span class="attribute"><font color="#ff0000">src</font></span><span><font color="#000000">=</font></span><span class="attribute-value">"test.php?codebar=BCGcode39&text=20090729"</span><span class="tag"><strong><font color="#006699">></font></strong></span><span><font color="#000000"> </font></span></span></li></ol>
Copy after login
<span style="COLOR: #0000ff"></span>PHP5生成条形码效果图:
Copy after login

498)this.width=498;' onmousewheel = 'javascript:return big(this)' alt=运行实例效果图 src="http://www.bkjia.com/uploadfile/2013/0904/20130904094617379.jpg" width=665 height=186>

PHP5生成条形码test.php代码:

<span style="COLOR: #0000ff"><pre class="brush:php;toolbar:false"><ol class="dp-c">
<li class="alt"><span><span><font color="#000000"><?php  </FONT></font></span></span></li>
<li>
<span></span><span class="comment"><font color="#008200">// Including all required classes </font></span><span><font color="#000000"> </font></span>
</li>
</ol>
Copy after login
  • require('class/BCGFont.php');  
  • require('class/BCGColor.php');  
  • require('class/BCGDrawing.php');  
  • /*'BCGcodabar','BCGcode11','BCGcode39','BCGcode39extended','BCGcode93',  
  • 'BCGcode128','BCGean8','BCGean13','BCGisbn','BCGi25','BCGs25','BCGmsi',  
  • 'BCGupca','BCGupce','BCGupcext2','BCGupcext5','BCGpostnet','BCGothercode'*/ 
  • $codebar = $_REQUEST['codebar']; //该软件支持的所有编码,只需调整$codebar参数即可。  
  • // Including the barcode technology  
  • include('class/'.$codebar.'.barcode.php');  
  • // Loading Font  
  • $font = new BCGFont('./class/font/Arial.ttf', 10);  
  • // The arguments are R, G, B for color.  
  • $color_black = new BCGColor(0, 0, 0);  
  • $color_white = new BCGColor(255, 255, 255);  
  • $code = new $codebar();  
  • $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)  
  • $text = $_REQUEST['text']; //PHP5生成条形码将要数据的内容  
  • $code->parse($text);  
  • /* Here is the list of the arguments  
  • 1 - Filename (empty : display on screen)  
  • 2 - Background color */ 
  • $drawing = new BCGDrawing(''$color_white);  
  • $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');  
  • // Draw (or save) the image into PNG format.  
  • $drawing->finish(BCGDrawing::IMG_FORMAT_PNG);  
  • ?> 
  • 在运行过程中出现异常";
    throw $e; //重掷异常
    }
    }
    ?﹥
    Copy after login


    Statement of this Website
    The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

    Hot AI Tools

    Undresser.AI Undress

    Undresser.AI Undress

    AI-powered app for creating realistic nude photos

    AI Clothes Remover

    AI Clothes Remover

    Online AI tool for removing clothes from photos.

    Undress AI Tool

    Undress AI Tool

    Undress images for free

    Clothoff.io

    Clothoff.io

    AI clothes remover

    AI Hentai Generator

    AI Hentai Generator

    Generate AI Hentai for free.

    Hot Article

    R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
    2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
    Repo: How To Revive Teammates
    4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
    Hello Kitty Island Adventure: How To Get Giant Seeds
    3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

    Hot Tools

    Notepad++7.3.1

    Notepad++7.3.1

    Easy-to-use and free code editor

    SublimeText3 Chinese version

    SublimeText3 Chinese version

    Chinese version, very easy to use

    Zend Studio 13.0.1

    Zend Studio 13.0.1

    Powerful PHP integrated development environment

    Dreamweaver CS6

    Dreamweaver CS6

    Visual web development tools

    SublimeText3 Mac version

    SublimeText3 Mac version

    God-level code editing software (SublimeText3)

    What software is crystaldiskmark? -How to use crystaldiskmark? What software is crystaldiskmark? -How to use crystaldiskmark? Mar 18, 2024 pm 02:58 PM

    CrystalDiskMark is a small HDD benchmark tool for hard drives that quickly measures sequential and random read/write speeds. Next, let the editor introduce CrystalDiskMark to you and how to use crystaldiskmark~ 1. Introduction to CrystalDiskMark CrystalDiskMark is a widely used disk performance testing tool used to evaluate the read and write speed and performance of mechanical hard drives and solid-state drives (SSD). Random I/O performance. It is a free Windows application and provides a user-friendly interface and various test modes to evaluate different aspects of hard drive performance and is widely used in hardware reviews

    CrystalDiskinfo usage tutorial-What software is CrystalDiskinfo? CrystalDiskinfo usage tutorial-What software is CrystalDiskinfo? Mar 18, 2024 pm 04:50 PM

    CrystalDiskInfo is a software used to check computer hardware devices. In this software, we can check our own computer hardware, such as reading speed, transmission mode, interface, etc.! So in addition to these functions, how to use CrystalDiskInfo and what exactly is CrystalDiskInfo? Let me sort it out for you! 1. The Origin of CrystalDiskInfo As one of the three major components of a computer host, a solid-state drive is the storage medium of a computer and is responsible for computer data storage. A good solid-state drive can speed up file reading and affect consumer experience. When consumers receive new devices, they can use third-party software or other SSDs to

    Interpret the meaning and difference of PHP version NTS Interpret the meaning and difference of PHP version NTS Mar 27, 2024 am 11:48 AM

    The meaning and difference of PHP version NTS PHP is a popular server-side scripting language that is widely used in the field of web development. There are two main versions of PHP: ThreadSafe(TS) and Non-ThreadSafe(NTS). On the official website of PHP, we can see two different PHP download versions, namely PHPNTS and PHPTS. So, what does PHP version NTS mean? What is the difference between it and the TS version? Next,

    How to resolve an incompatible software attempt to load with Edge? How to resolve an incompatible software attempt to load with Edge? Mar 15, 2024 pm 01:34 PM

    When we use the Edge browser, sometimes incompatible software attempts to be loaded together, so what is going on? Let this site carefully introduce to users how to solve the problem of trying to load incompatible software with Edge. How to solve an incompatible software trying to load with Edge Solution 1: Search IE in the start menu and access it directly with IE. Solution 2: Note: Modifying the registry may cause system failure, so operate with caution. Modify registry parameters. 1. Enter regedit during operation. 2. Find the path\HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Micros

    750,000 rounds of one-on-one battle between large models, GPT-4 won the championship, and Llama 3 ranked fifth 750,000 rounds of one-on-one battle between large models, GPT-4 won the championship, and Llama 3 ranked fifth Apr 23, 2024 pm 03:28 PM

    Regarding Llama3, new test results have been released - the large model evaluation community LMSYS released a large model ranking list. Llama3 ranked fifth, and tied for first place with GPT-4 in the English category. The picture is different from other benchmarks. This list is based on one-on-one battles between models, and the evaluators from all over the network make their own propositions and scores. In the end, Llama3 ranked fifth on the list, followed by three different versions of GPT-4 and Claude3 Super Cup Opus. In the English single list, Llama3 overtook Claude and tied with GPT-4. Regarding this result, Meta’s chief scientist LeCun was very happy and forwarded the tweet and

    What software is photoshopcs5? -photoshopcs5 usage tutorial What software is photoshopcs5? -photoshopcs5 usage tutorial Mar 19, 2024 am 09:04 AM

    PhotoshopCS is the abbreviation of Photoshop Creative Suite. It is a software produced by Adobe and is widely used in graphic design and image processing. As a novice learning PS, let me explain to you today what software photoshopcs5 is and how to use photoshopcs5. 1. What software is photoshop cs5? Adobe Photoshop CS5 Extended is ideal for professionals in film, video and multimedia fields, graphic and web designers who use 3D and animation, and professionals in engineering and scientific fields. Render a 3D image and merge it into a 2D composite image. Edit videos easily

    How to lower the chrome browser version? How to return chrome to the previous version How to lower the chrome browser version? How to return chrome to the previous version Mar 14, 2024 am 09:22 AM

    The Chrome browser is currently the browser with the largest number of users and high praise, and is committed to providing users with a comprehensive and fast experience. Some netizens feel that the old version is still easier to use after updating Google Chrome. If they want to downgrade the version of Google Chrome, what should they do? Let’s take a look at the detailed operation method of downgrading Google Chrome! The specific method of downgrading Chrome is to close the Chrome process, open the directory where chrome.exe is located (Application), delete chrome.exe, rename old_chrome.exe to chrome.exe, and delete the \UserData\Default\Web Data file (do not delete this

    What software is coreldraw - how to download the official free version of cdr2022? What software is coreldraw - how to download the official free version of cdr2022? Mar 18, 2024 pm 11:00 PM

    CorelDRAW software is a vector graphics production tool software produced by Corel. It is mainly used for vector graphics, page design and image editing. Next, let the editor introduce to you what software coreldraw is? How to download the official free version of cdr2022! 1. What software is coreldraw? The origin of CorelDRAW. The full name of CorelDRAW software is CorelDRAW. It is a graphic design software for producing vector graphics. CorelDRAWX4 has been updated and optimized in text format, new interactive tables and page layer functions. CorelDRAWX4 supports online service integration and collaboration. As a graphic image tool and vector drawing software, it

    See all articles