Home Backend Development PHP Tutorial A simple example of generating barcodes with PHP5_PHP Tutorial

A simple example of generating barcodes with PHP5_PHP Tutorial

Jul 15, 2016 pm 01:26 PM
php5 and Example support yes barcode Version generate use of Simple software

The software supports both PHP4 and PHP5 versions. The PHP5 version is used in this article. Be sure to turn on PHP's GD module before use. This is php_gd2.dll in Windows and gd.so in Linux. Extract the compressed file to Apache and execute http://localhost/barcode/index.php. PHP5 generates barcodes as shown below:

1. Type: Select the barcode type

2. Output: Output image format

3. Thickness: Barcode height

4. Resolution: barcode size

5. Font: text size below the barcode, or no text displayed

6. Text: barcode printed content

barcode

Of course, this PHP5 barcode generation program only generates text into barcodes, but it cannot be flexibly embedded in other PHP programs when used. I will compress the test in the package Some adjustments have been made to .php to make it flexible for use in other programs. When running, just pass the barcode type and text to test.php, for example:
http://localhost/barcode/test.php?codebar=BCGcode39&text=20090729

Or run http://localhost/barcode/mytest.php

mytest.php code:

<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><SPAN class=tag-name>img</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>></span></font></strong></span><span><font color="#000000"> </font></span>
</li></ol>
Copy after login
<span style="COLOR: #0000ff"></span>PHP5生成条形码效果图:
Copy after login

Running

PHP5 generates barcode test.php code:

<span style="COLOR: #0000ff"><pre class="brush:php;toolbar:false"><ol class="dp-c">
<li class="alt"><span><span><font color="#000000"><?php  </FONT></SPAN></SPAN><LI><SPAN></SPAN><SPAN class=comment><FONT color=#008200>// Including all required classes </FONT></SPAN><SPAN><FONT color=#000000> </FONT></SPAN></SPAN><LI class=alt><SPAN></SPAN><SPAN class=keyword><STRONG><FONT color=#006699>require</FONT></STRONG></SPAN><SPAN><FONT color=#000000>(</FONT></SPAN><SPAN class=string>'class/BCGFont.php'</SPAN><SPAN><FONT color=#000000>);  </FONT></SPAN></SPAN><LI><SPAN></SPAN><SPAN class=keyword><STRONG><FONT color=#006699>require</FONT></STRONG></SPAN><SPAN><FONT color=#000000>(</FONT></SPAN><SPAN class=string>'class/BCGColor.php'</SPAN><SPAN><FONT color=#000000>);  </FONT></SPAN></SPAN><LI class=alt><SPAN></SPAN><SPAN class=keyword><STRONG><FONT color=#006699>require</FONT></STRONG></SPAN><SPAN><FONT color=#000000>(</FONT></SPAN><SPAN class=string>'class/BCGDrawing.php'</SPAN><SPAN><FONT color=#000000>);  </FONT></SPAN></SPAN><LI><SPAN></SPAN><SPAN class=comment><FONT color=#008200>/*'BCGcodabar','BCGcode11','BCGcode39','BCGcode39extended','BCGcode93', </FONT></SPAN> </SPAN><LI class=alt><SPAN><SPAN class=comment><FONT color=#008200>'BCGcode128','BCGean8','BCGean13','BCGisbn','BCGi25','BCGs25','BCGmsi', </FONT></SPAN><FONT color=#000000> </FONT></SPAN><LI><SPAN><SPAN class=comment><FONT color=#008200>'BCGupca','BCGupce','BCGupcext2','BCGupcext5','BCGpostnet','BCGothercode'*/</FONT></SPAN><SPAN><FONT color=#000000> </FONT></SPAN></SPAN><LI class=alt><SPAN></SPAN><SPAN class=vars><FONT color=#dd0000>$codebar</FONT></SPAN><SPAN><FONT color=#000000> = </FONT></SPAN><SPAN class=vars><FONT color=#dd0000>$_REQUEST</FONT></SPAN><SPAN><FONT color=#000000>[</FONT></SPAN><SPAN class=string>'codebar'</SPAN><SPAN><FONT color=#000000>]; </FONT></SPAN><SPAN class=comment><FONT color=#008200>//该软件支持的所有编码,只需调整$codebar参数即可。 </FONT></SPAN><SPAN><FONT color=#000000> </FONT></SPAN></SPAN><LI><SPAN></SPAN><SPAN class=comment><FONT color=#008200>// Including the barcode technology </FONT></SPAN><SPAN><FONT color=#000000> </FONT></SPAN></SPAN><LI class=alt><SPAN></SPAN><SPAN class=keyword><STRONG><FONT color=#006699>include</FONT></STRONG></SPAN><SPAN><FONT color=#000000>(</FONT></SPAN><SPAN class=string>'class/'</SPAN><SPAN><FONT color=#000000>.</FONT></SPAN><SPAN class=vars><FONT color=#dd0000>$codebar</FONT></SPAN><SPAN><FONT color=#000000>.</FONT></SPAN><SPAN class=string>'.barcode.php'</SPAN><SPAN><FONT color=#000000>);  </FONT></SPAN></SPAN><LI><SPAN></SPAN><SPAN class=comment><FONT color=#008200>// Loading Font </FONT></SPAN><SPAN><FONT color=#000000> </FONT></SPAN></SPAN><LI class=alt><SPAN></SPAN><SPAN class=vars><FONT color=#dd0000>$font</FONT></SPAN><SPAN><FONT color=#000000> = </FONT></SPAN><SPAN class=keyword><STRONG><FONT color=#006699>new</FONT></STRONG></SPAN><SPAN><FONT color=#000000> BCGFont(</FONT></SPAN><SPAN class=string>'./class/font/Arial.ttf'</SPAN><SPAN><FONT color=#000000>, 10);  </FONT></SPAN></SPAN><LI><SPAN></SPAN><SPAN class=comment><FONT color=#008200>// The arguments are R, G, B for color. </FONT></SPAN><SPAN><FONT color=#000000> </FONT></SPAN></SPAN><LI class=alt><SPAN></SPAN><SPAN class=vars><FONT color=#dd0000>$color_black</FONT></SPAN><SPAN><FONT color=#000000> = </FONT></SPAN><SPAN class=keyword><STRONG><FONT color=#006699>new</FONT></STRONG></SPAN><SPAN><FONT color=#000000> BCGColor(0, 0, 0);  </FONT></SPAN></SPAN><LI><SPAN></SPAN><SPAN class=vars><FONT color=#dd0000>$color_white</FONT></SPAN><SPAN><FONT color=#000000> = </FONT></SPAN><SPAN class=keyword><STRONG><FONT color=#006699>new</FONT></STRONG></SPAN><SPAN><FONT color=#000000> BCGColor(255, 255, 255);  </FONT></SPAN></SPAN><LI class=alt><SPAN></SPAN><SPAN class=vars><FONT color=#dd0000>$code</FONT></SPAN><SPAN><FONT color=#000000> = </FONT></SPAN><SPAN class=keyword><STRONG><FONT color=#006699>new</FONT></STRONG></SPAN><SPAN><FONT color=#000000> </FONT></SPAN><SPAN class=vars><FONT color=#dd0000>$codebar</FONT></SPAN><SPAN><FONT color=#000000>();  </FONT></SPAN></SPAN><LI><SPAN></SPAN><SPAN class=vars><FONT color=#dd0000>$code</FONT></SPAN><SPAN><FONT color=#000000>->setScale(2); </font></span><span class="comment"><font color="#008200">// Resolution </font></span><span><font color="#000000"> </font></span></span></li>
<li class="alt">
<span></span><span class="vars"><font color="#dd0000">$code</font></span><span><font color="#000000">->setThickness(30); </font></span><span class="comment"><font color="#008200">// Thickness </font></span><span><font color="#000000"> </font></span>
</li>
</ol>
Copy after login
  • $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);  
  • ?> 
  • Exception occurred during operation";
    throw $e; //Rethrow exception
    }
    }
    ?﹥
    Copy after login


    www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/446609.htmlTechArticleThe software supports both PHP4 and PHP5 versions. The PHP5 version is used in this article. Be sure to turn on PHP's GD module before use. This is php_gd2.dll in Windows and gd.so in Linux. Will compress...
    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 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

    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

    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

    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,

    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

    Which version of Douyin matrix management system is recommended? How to do matrix marketing? Which version of Douyin matrix management system is recommended? How to do matrix marketing? Mar 21, 2024 pm 03:50 PM

    With the popularity of Douyin, more and more companies and individuals have begun to use Douyin for marketing. As an important tool for Douyin marketing, the Douyin matrix management system has also received widespread attention. So, which version of Douyin matrix management system is recommended? This article will answer this question for you and introduce how to play Douyin matrix marketing. 1. Which version of Douyin matrix management system is recommended? There are many versions of the Douyin matrix management system. The following versions are currently popular on the market: Douyin’s official version of the matrix management system is specially designed for companies with certain operating experience and budget, and can realize multi-account management, data Analysis and material library functions. This system provides an efficient way to manage Douyin accounts and helps companies better understand their operational data to better

    See all articles