Home Backend Development PHP Problem How to generate different barcodes in php

How to generate different barcodes in php

Oct 31, 2022 am 09:53 AM
php barcode

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.

How to generate different barcodes in php

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
Copy after login

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 &#39;<p>Example - QrCode</p>&#39;;
        $qrCode = new QrCode();
        $qrCode
            ->setText(&#39;https://www.php.net/manual/zh/&#39;)
            ->setSize(300)
            ->setPadding(10)
            ->setErrorCorrection(&#39;high&#39;)
            ->setForegroundColor(array(&#39;r&#39; => 0, &#39;g&#39; => 0, &#39;b&#39; => 0, &#39;a&#39; => 0))
            ->setBackgroundColor(array(&#39;r&#39; => 255, &#39;g&#39; => 255, &#39;b&#39; => 255, &#39;a&#39; => 0))
            ->setLabel(&#39;https://www.php.net/&#39;)
            ->setLabelFontSize(16)
            ->setImageType(QrCode::IMAGE_TYPE_PNG);
        echo &#39;<img  src="/static/imghw/default1.png"  data-src="data:&#39; . $qrCode- alt="How to generate different barcodes in php" >getContentType() . &#39;;base64,&#39; . $qrCode->generate() . &#39;"  class="lazy"   />&#39;;
 
        echo &#39;<hr>&#39;;
        echo &#39;<p>Example - Code128</p>&#39;;
        $barcode = new BarcodeGenerator();
        $barcode->setText("0123456789");
        $barcode->setType(BarcodeGenerator::Code128);
        $barcode->setScale(2);
        $barcode->setThickness(25);
        $barcode->setFontSize(10);
        $code = $barcode->generate();
        echo &#39;<img  src="/static/imghw/default1.png"  data-src="https://img-blog.csdnimg.cn/2022010611514192897.png&#39; . $code . &#39;"  class="lazy"   / alt="How to generate different barcodes in php" >&#39;;
 
        echo &#39;<hr>&#39;;
        echo &#39;<p>Example - Code11</p>&#39;;
        $barcode = new BarcodeGenerator();
        $barcode->setText("0123456789");
        $barcode->setType(BarcodeGenerator::Code11);
        $code = $barcode->generate();
        echo &#39;<img  src="/static/imghw/default1.png"  data-src="https://img-blog.csdnimg.cn/2022010611514192897.png&#39; . $code . &#39;"  class="lazy"   / alt="How to generate different barcodes in php" >&#39;;
 
        echo &#39;<hr>&#39;;
        echo &#39;<p>Example - Code39</p>&#39;;
        $barcode = new BarcodeGenerator();
        $barcode->setText("0123456789");
        $barcode->setType(BarcodeGenerator::Code39);
        $code = $barcode->generate();
        echo &#39;<img  src="/static/imghw/default1.png"  data-src="https://img-blog.csdnimg.cn/2022010611514192897.png&#39; . $code . &#39;"  class="lazy"   / alt="How to generate different barcodes in php" >&#39;;
 
        echo &#39;<hr>&#39;;
        echo &#39;<p>Example - Code39Extended</p>&#39;;
        $barcode = new BarcodeGenerator();
        $barcode->setText("0123456789");
        $barcode->setType(BarcodeGenerator::Code39Extended);
        $code = $barcode->generate();
        echo &#39;<img  src="/static/imghw/default1.png"  data-src="https://img-blog.csdnimg.cn/2022010611514192897.png&#39; . $code . &#39;"  class="lazy"   / alt="How to generate different barcodes in php" >&#39;;
 
        echo &#39;<hr>&#39;;
        echo &#39;<p>Example - Ean128</p>&#39;;
        $barcode = new BarcodeGenerator();
        $barcode->setText("00123456789012345675");
        $barcode->setType(BarcodeGenerator::Ean128);
        $code = $barcode->generate();
        echo &#39;<img  src="/static/imghw/default1.png"  data-src="https://img-blog.csdnimg.cn/2022010611514192897.png&#39; . $code . &#39;"  class="lazy"   / alt="How to generate different barcodes in php" >&#39;;
 
        echo &#39;<hr>&#39;;
        echo &#39;<p>Example - Gs1128</p>&#39;;
        $barcode = new BarcodeGenerator();
        $barcode->setText("00123456789012345675");
        $barcode->setType(BarcodeGenerator::Gs1128);
        $code = $barcode->generate();
        echo &#39;<img  src="/static/imghw/default1.png"  data-src="https://img-blog.csdnimg.cn/2022010611514192897.png&#39; . $code . &#39;"  class="lazy"   / alt="How to generate different barcodes in php" >&#39;;
 
        echo &#39;<hr>&#39;;
        echo &#39;<p>Example - Gs1128</p>&#39;;
        $barcode = new BarcodeGenerator();
        $barcode->setText("4157707266014651802001012603068039000000006377069620171215");
        $barcode->setType(BarcodeGenerator::Gs1128);
        $barcode->setNoLengthLimit(true);
        $barcode->setAllowsUnknownIdentifier(true);
        $code = $barcode->generate();
        echo &#39;<img  src="/static/imghw/default1.png"  data-src="https://img-blog.csdnimg.cn/2022010611514192897.png&#39; . $code . &#39;"  class="lazy"   / alt="How to generate different barcodes in php" >&#39;;
 
        echo &#39;<hr>&#39;;
        echo &#39;<p>Example - I25</p>&#39;;
        $barcode = new BarcodeGenerator();
        $barcode->setText("00123456789012345675");
        $barcode->setType(BarcodeGenerator::I25);
        $code = $barcode->generate();
        echo &#39;<img  src="/static/imghw/default1.png"  data-src="https://img-blog.csdnimg.cn/2022010611514192897.png&#39; . $code . &#39;"  class="lazy"   / alt="How to generate different barcodes in php" >&#39;;
 
        echo &#39;<hr>&#39;;
        echo &#39;<p>Example - Isbn</p>&#39;;
        $barcode = new BarcodeGenerator();
        $barcode->setText("0012345678901");
        $barcode->setType(BarcodeGenerator::Isbn);
        $code = $barcode->generate();
        echo &#39;<img  src="/static/imghw/default1.png"  data-src="https://img-blog.csdnimg.cn/2022010611514192897.png&#39; . $code . &#39;"  class="lazy"   / alt="How to generate different barcodes in php" >&#39;;
 
        echo &#39;<hr>&#39;;
        echo &#39;<p>Example - Msi</p>&#39;;
        $barcode = new BarcodeGenerator();
        $barcode->setText("0012345678901");
        $barcode->setType(BarcodeGenerator::Msi);
        $code = $barcode->generate();
        echo &#39;<img  src="/static/imghw/default1.png"  data-src="https://img-blog.csdnimg.cn/2022010611514192897.png&#39; . $code . &#39;"  class="lazy"   / alt="How to generate different barcodes in php" >&#39;;
 
        echo &#39;<hr>&#39;;
        echo &#39;<p>Example - Postnet</p>&#39;;
        $barcode = new BarcodeGenerator();
        $barcode->setText("01234567890");
        $barcode->setType(BarcodeGenerator::Postnet);
        $code = $barcode->generate();
        echo &#39;<img  src="/static/imghw/default1.png"  data-src="https://img-blog.csdnimg.cn/2022010611514192897.png&#39; . $code . &#39;"  class="lazy"   / alt="How to generate different barcodes in php" >&#39;;
 
        echo &#39;<hr>&#39;;
        echo &#39;<p>Example - S25</p>&#39;;
        $barcode = new BarcodeGenerator();
        $barcode->setText("012345678901");
        $barcode->setType(BarcodeGenerator::S25);
        $code = $barcode->generate();
        echo &#39;<img  src="/static/imghw/default1.png"  data-src="https://img-blog.csdnimg.cn/2022010611514192897.png&#39; . $code . &#39;"  class="lazy"   / alt="How to generate different barcodes in php" >&#39;;
 
        echo &#39;<hr>&#39;;
        echo &#39;<p>Example - Upca</p>&#39;;
        $barcode = new BarcodeGenerator();
        $barcode->setText("012345678901");
        $barcode->setType(BarcodeGenerator::Upca);
        $code = $barcode->generate();
        echo &#39;<img  src="/static/imghw/default1.png"  data-src="https://img-blog.csdnimg.cn/2022010611514192897.png&#39; . $code . &#39;"  class="lazy"   / alt="How to generate different barcodes in php" >&#39;;
 
        echo &#39;<hr>&#39;;
        echo &#39;<p>Example - Upce</p>&#39;;
        $barcode = new BarcodeGenerator();
        $barcode->setText("012345");
        $barcode->setType(BarcodeGenerator::Upce);
        $code = $barcode->generate();
        echo &#39;<img  src="/static/imghw/default1.png"  data-src="https://img-blog.csdnimg.cn/2022010611514192897.png&#39; . $code . &#39;"  class="lazy"   / alt="How to generate different barcodes in php" >&#39;;
 
    }
}
Copy after login

How to generate different barcodes in php

How to convert image data in base64 format into images

// $base_img是获取到前端传递的值
            $base_img = str_replace(&#39;data:image/jpg;base64,&#39;, &#39;&#39;, $code);
//  设置文件路径和命名文件名称
            $path = "D:/Uploads/Bar/2019-12-11/";
            $output_file = time().rand(100,999).&#39;.jpg&#39;;
            $path = $path.$output_file;
//  创建将数据流文件写入我们创建的文件内容中
            file_put_contents($path, base64_decode($base_img));
// 输出文件
            print_r($output_file);
Buy me a cup of coffee :)
Copy after login

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!

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

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

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)

PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian Dec 24, 2024 pm 04:42 PM

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

How To Set Up Visual Studio Code (VS Code) for PHP Development How To Set Up Visual Studio Code (VS Code) for PHP Development Dec 20, 2024 am 11:31 AM

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

7 PHP Functions I Regret I Didn't Know Before 7 PHP Functions I Regret I Didn't Know Before Nov 13, 2024 am 09:42 AM

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

How do you parse and process HTML/XML in PHP? How do you parse and process HTML/XML in PHP? Feb 07, 2025 am 11:57 AM

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

Explain JSON Web Tokens (JWT) and their use case in PHP APIs. Explain JSON Web Tokens (JWT) and their use case in PHP APIs. Apr 05, 2025 am 12:04 AM

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,

PHP Program to Count Vowels in a String PHP Program to Count Vowels in a String Feb 07, 2025 pm 12:12 PM

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

Explain late static binding in PHP (static::). Explain late static binding in PHP (static::). Apr 03, 2025 am 12:04 AM

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 PHP magic methods (__construct, __destruct, __call, __get, __set, etc.) and provide use cases? What are PHP magic methods (__construct, __destruct, __call, __get, __set, etc.) and provide use cases? Apr 03, 2025 am 12:03 AM

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.

See all articles