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/imghwm/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/imghwm/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/imghwm/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/imghwm/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/imghwm/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/imghwm/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/imghwm/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/imghwm/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/imghwm/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/imghwm/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/imghwm/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/imghwm/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/imghwm/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/imghwm/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/imghwm/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!

The article compares ACID and BASE database models, detailing their characteristics and appropriate use cases. ACID prioritizes data integrity and consistency, suitable for financial and e-commerce applications, while BASE focuses on availability and

The article discusses securing PHP file uploads to prevent vulnerabilities like code injection. It focuses on file type validation, secure storage, and error handling to enhance application security.

Article discusses best practices for PHP input validation to enhance security, focusing on techniques like using built-in functions, whitelist approach, and server-side validation.

The article discusses strategies for implementing API rate limiting in PHP, including algorithms like Token Bucket and Leaky Bucket, and using libraries like symfony/rate-limiter. It also covers monitoring, dynamically adjusting rate limits, and hand

The article discusses the benefits of using password_hash and password_verify in PHP for securing passwords. The main argument is that these functions enhance password protection through automatic salt generation, strong hashing algorithms, and secur

The article discusses OWASP Top 10 vulnerabilities in PHP and mitigation strategies. Key issues include injection, broken authentication, and XSS, with recommended tools for monitoring and securing PHP applications.

The article discusses strategies to prevent XSS attacks in PHP, focusing on input sanitization, output encoding, and using security-enhancing libraries and frameworks.

The article discusses the use of interfaces and abstract classes in PHP, focusing on when to use each. Interfaces define a contract without implementation, suitable for unrelated classes and multiple inheritance. Abstract classes provide common funct


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

Dreamweaver CS6
Visual web development tools

WebStorm Mac version
Useful JavaScript development tools

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

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