How to generate different barcodes in php
How to generate different barcodes in php: 1. Install the required code library through the "composer require codeitnowin/barcode" statement; 2. Write the data flow file into the content of the created file; 3. Output the picture Just file.
The operating environment of this tutorial: Windows 7 system, PHP version 8.1, Dell G3 computer.
php How to generate different barcodes?
php Generate barcode:
Barcode (barcode) is to arrange multiple black bars and blanks with different widths according to certain encoding rules. Use A graphical identifier that expresses a set of information.
This is implemented using PHP and supports most coding systems.
Barcode length
Code128, Code39 Extended, Code93 Extended supports all ASCII codes.
Code128 has three character sets: A, B, and C. Each character set supports part of it, roughly like this.
A character set supports AZ 26 uppercase letters, 09 9 Numbers and some special characters;
B character set supports AZ 26 uppercase and lowercase letters, 09 9 numbers and some special characters;
C character set supports pure numeric characters and 0` 9 9 numbers, and it is an even number. If it is an odd number, 0 will be automatically added in front when generating the barcode; the maximum length of pure characters is 32 bits, and pure characters plus special symbols are 44 bits. EAN/UCC 128 is the same as Code 128.
CODE128 code is a barcode system widely used in enterprise internal management, production processes, and logistics control systems. Due to its excellent characteristics, it is widely used in the design of management information systems. Use, CODE128 code is one of the most widely used barcode coding systems.
CODE128 code is a high-density barcode introduced in 1981. CODE128 code can represent a total of 128 characters from ASCII 0 to ASCII 127, so it is called 128 code. It contains numbers, letters and symbolic characters.
Code 128 code and Code 39 code have many similarities, and both are widely used in corporate internal management, production processes, and logistics control systems. The difference is that Code 128 can represent more characters than Code 39, and the coding density per unit length is higher. When Code 39 encoding cannot be accommodated in the unit length or the encoded characters exceed the limits of Code 39, Code 128 can be selected for encoding.
Code39, Code93 support the range of 09 numeric characters and AZ uppercase letters and '/', ' ', '%', '$', '-', '.' and spaces, the length is theoretically unlimited limit.
Code39 Extended, Code93 Extended does not support ‘-’, ‘.’, others are the same as 39 93.
EAN8,EAN13,EAN Ext,UPC A,UPC E,UPC Ext supports the range of 0`9 numeric characters, the length of EAN8 is 8, the length of EAN13 is 13, the length of EAN8 Ext is 10 or 13, EAN13 The Ext length is 15 or 18, the UPCA length is 12, the UPCE length is 8, the UPCE Ext length is 10 or 13, and the UPCA Ext length is 14 or 17.
Bookland, ISSN, ISSN may support characters other than numbers. For support of this middleware, please refer to the description in the "About Bookland (ISBN) and ISSN" section.
Code11 supports the range of 0`9 numeric characters and ‘-’, and the length is theoretically unlimited.
Codabar supports the range of 0`9 numeric characters and 'A', 'B', 'C', 'D', '-', '.', '/', ':', ' ', '$', the starting and ending characters must be characters in 'A', 'B', 'C', 'D', and the length is theoretically not limited.
MSI, Code 2of5 supports a range of 0`9 numeric characters, and the length is theoretically unlimited.
PostNet supports a range of 0`9 numeric characters, with a length of 5, 9, or 11 digits. This development kit supports formats with non-numeric characters, such as 12345-8012, which is more convenient to use.
Matrix 25 (matrix 25 code) supports a range of 0`9 numeric characters and a length of 13 digits.
Install the required code libraries
composer require codeitnowin/barcode
Baidu Cloud address: https://pan.baidu.com/s/1-hFWYfed4y3YkWKLz2o75g
Related code (specifically shown below)
<?php namespace App\Http\Controllers; use Illuminate\Http\Request; use CodeItNow\BarcodeBundle\Utils\BarcodeGenerator; use CodeItNow\BarcodeBundle\Utils\QrCode; class BarCodeController extends Controller { public function index() { echo '<p>Example - QrCode</p>'; $qrCode = new QrCode(); $qrCode ->setText('https://www.php.net/manual/zh/') ->setSize(300) ->setPadding(10) ->setErrorCorrection('high') ->setForegroundColor(array('r' => 0, 'g' => 0, 'b' => 0, 'a' => 0)) ->setBackgroundColor(array('r' => 255, 'g' => 255, 'b' => 255, 'a' => 0)) ->setLabel('https://www.php.net/') ->setLabelFontSize(16) ->setImageType(QrCode::IMAGE_TYPE_PNG); echo '<img src="/static/imghw/default1.png" data-src="data:' . $qrCode- alt="How to generate different barcodes in php" >getContentType() . ';base64,' . $qrCode->generate() . '" class="lazy" />'; echo '<hr>'; echo '<p>Example - Code128</p>'; $barcode = new BarcodeGenerator(); $barcode->setText("0123456789"); $barcode->setType(BarcodeGenerator::Code128); $barcode->setScale(2); $barcode->setThickness(25); $barcode->setFontSize(10); $code = $barcode->generate(); echo '<img src="/static/imghw/default1.png" data-src="https://img-blog.csdnimg.cn/2022010611514192897.png' . $code . '" class="lazy" / alt="How to generate different barcodes in php" >'; echo '<hr>'; echo '<p>Example - Code11</p>'; $barcode = new BarcodeGenerator(); $barcode->setText("0123456789"); $barcode->setType(BarcodeGenerator::Code11); $code = $barcode->generate(); echo '<img src="/static/imghw/default1.png" data-src="https://img-blog.csdnimg.cn/2022010611514192897.png' . $code . '" class="lazy" / alt="How to generate different barcodes in php" >'; echo '<hr>'; echo '<p>Example - Code39</p>'; $barcode = new BarcodeGenerator(); $barcode->setText("0123456789"); $barcode->setType(BarcodeGenerator::Code39); $code = $barcode->generate(); echo '<img src="/static/imghw/default1.png" data-src="https://img-blog.csdnimg.cn/2022010611514192897.png' . $code . '" class="lazy" / alt="How to generate different barcodes in php" >'; echo '<hr>'; echo '<p>Example - Code39Extended</p>'; $barcode = new BarcodeGenerator(); $barcode->setText("0123456789"); $barcode->setType(BarcodeGenerator::Code39Extended); $code = $barcode->generate(); echo '<img src="/static/imghw/default1.png" data-src="https://img-blog.csdnimg.cn/2022010611514192897.png' . $code . '" class="lazy" / alt="How to generate different barcodes in php" >'; echo '<hr>'; echo '<p>Example - Ean128</p>'; $barcode = new BarcodeGenerator(); $barcode->setText("00123456789012345675"); $barcode->setType(BarcodeGenerator::Ean128); $code = $barcode->generate(); echo '<img src="/static/imghw/default1.png" data-src="https://img-blog.csdnimg.cn/2022010611514192897.png' . $code . '" class="lazy" / alt="How to generate different barcodes in php" >'; echo '<hr>'; echo '<p>Example - Gs1128</p>'; $barcode = new BarcodeGenerator(); $barcode->setText("00123456789012345675"); $barcode->setType(BarcodeGenerator::Gs1128); $code = $barcode->generate(); echo '<img src="/static/imghw/default1.png" data-src="https://img-blog.csdnimg.cn/2022010611514192897.png' . $code . '" class="lazy" / alt="How to generate different barcodes in php" >'; echo '<hr>'; echo '<p>Example - Gs1128</p>'; $barcode = new BarcodeGenerator(); $barcode->setText("4157707266014651802001012603068039000000006377069620171215"); $barcode->setType(BarcodeGenerator::Gs1128); $barcode->setNoLengthLimit(true); $barcode->setAllowsUnknownIdentifier(true); $code = $barcode->generate(); echo '<img src="/static/imghw/default1.png" data-src="https://img-blog.csdnimg.cn/2022010611514192897.png' . $code . '" class="lazy" / alt="How to generate different barcodes in php" >'; echo '<hr>'; echo '<p>Example - I25</p>'; $barcode = new BarcodeGenerator(); $barcode->setText("00123456789012345675"); $barcode->setType(BarcodeGenerator::I25); $code = $barcode->generate(); echo '<img src="/static/imghw/default1.png" data-src="https://img-blog.csdnimg.cn/2022010611514192897.png' . $code . '" class="lazy" / alt="How to generate different barcodes in php" >'; echo '<hr>'; echo '<p>Example - Isbn</p>'; $barcode = new BarcodeGenerator(); $barcode->setText("0012345678901"); $barcode->setType(BarcodeGenerator::Isbn); $code = $barcode->generate(); echo '<img src="/static/imghw/default1.png" data-src="https://img-blog.csdnimg.cn/2022010611514192897.png' . $code . '" class="lazy" / alt="How to generate different barcodes in php" >'; echo '<hr>'; echo '<p>Example - Msi</p>'; $barcode = new BarcodeGenerator(); $barcode->setText("0012345678901"); $barcode->setType(BarcodeGenerator::Msi); $code = $barcode->generate(); echo '<img src="/static/imghw/default1.png" data-src="https://img-blog.csdnimg.cn/2022010611514192897.png' . $code . '" class="lazy" / alt="How to generate different barcodes in php" >'; echo '<hr>'; echo '<p>Example - Postnet</p>'; $barcode = new BarcodeGenerator(); $barcode->setText("01234567890"); $barcode->setType(BarcodeGenerator::Postnet); $code = $barcode->generate(); echo '<img src="/static/imghw/default1.png" data-src="https://img-blog.csdnimg.cn/2022010611514192897.png' . $code . '" class="lazy" / alt="How to generate different barcodes in php" >'; echo '<hr>'; echo '<p>Example - S25</p>'; $barcode = new BarcodeGenerator(); $barcode->setText("012345678901"); $barcode->setType(BarcodeGenerator::S25); $code = $barcode->generate(); echo '<img src="/static/imghw/default1.png" data-src="https://img-blog.csdnimg.cn/2022010611514192897.png' . $code . '" class="lazy" / alt="How to generate different barcodes in php" >'; echo '<hr>'; echo '<p>Example - Upca</p>'; $barcode = new BarcodeGenerator(); $barcode->setText("012345678901"); $barcode->setType(BarcodeGenerator::Upca); $code = $barcode->generate(); echo '<img src="/static/imghw/default1.png" data-src="https://img-blog.csdnimg.cn/2022010611514192897.png' . $code . '" class="lazy" / alt="How to generate different barcodes in php" >'; echo '<hr>'; echo '<p>Example - Upce</p>'; $barcode = new BarcodeGenerator(); $barcode->setText("012345"); $barcode->setType(BarcodeGenerator::Upce); $code = $barcode->generate(); echo '<img src="/static/imghw/default1.png" data-src="https://img-blog.csdnimg.cn/2022010611514192897.png' . $code . '" class="lazy" / alt="How to generate different barcodes in php" >'; } }
How to convert image data in base64 format into images
// $base_img是获取到前端传递的值 $base_img = str_replace('data:image/jpg;base64,', '', $code); // 设置文件路径和命名文件名称 $path = "D:/Uploads/Bar/2019-12-11/"; $output_file = time().rand(100,999).'.jpg'; $path = $path.$output_file; // 创建将数据流文件写入我们创建的文件内容中 file_put_contents($path, base64_decode($base_img)); // 输出文件 print_r($output_file); Buy me a cup of coffee :)
Recommended learning: " PHP video tutorial》
The above is the detailed content of How to generate different barcodes in php. For more information, please follow other related articles on the PHP Chinese website!

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

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



PHP 8.4 brings several new features, security improvements, and performance improvements with healthy amounts of feature deprecations and removals. This guide explains how to install PHP 8.4 or upgrade to PHP 8.4 on Ubuntu, Debian, or their derivati

Visual Studio Code, also known as VS Code, is a free source code editor — or integrated development environment (IDE) — available for all major operating systems. With a large collection of extensions for many programming languages, VS Code can be c

If you are an experienced PHP developer, you might have the feeling that you’ve been there and done that already.You have developed a significant number of applications, debugged millions of lines of code, and tweaked a bunch of scripts to achieve op

This tutorial demonstrates how to efficiently process XML documents using PHP. XML (eXtensible Markup Language) is a versatile text-based markup language designed for both human readability and machine parsing. It's commonly used for data storage an

JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,

A string is a sequence of characters, including letters, numbers, and symbols. This tutorial will learn how to calculate the number of vowels in a given string in PHP using different methods. The vowels in English are a, e, i, o, u, and they can be uppercase or lowercase. What is a vowel? Vowels are alphabetic characters that represent a specific pronunciation. There are five vowels in English, including uppercase and lowercase: a, e, i, o, u Example 1 Input: String = "Tutorialspoint" Output: 6 explain The vowels in the string "Tutorialspoint" are u, o, i, a, o, i. There are 6 yuan in total

Static binding (static::) implements late static binding (LSB) in PHP, allowing calling classes to be referenced in static contexts rather than defining classes. 1) The parsing process is performed at runtime, 2) Look up the call class in the inheritance relationship, 3) It may bring performance overhead.

What are the magic methods of PHP? PHP's magic methods include: 1.\_\_construct, used to initialize objects; 2.\_\_destruct, used to clean up resources; 3.\_\_call, handle non-existent method calls; 4.\_\_get, implement dynamic attribute access; 5.\_\_set, implement dynamic attribute settings. These methods are automatically called in certain situations, improving code flexibility and efficiency.
