antwerpes/barcodes-1d
Composer 安装命令:
composer require antwerpes/barcodes-1d
包简介
Library for programmatically creating and rendering barcodes
README 文档
README
Barcodes 1D
Barcode generator written in PHP for encoding and rendering most common barcode formats to multiple image output formats.
Features
- Supports most common barcode formats (Code128, EAN, UPC, ...)
- Can render to SVG, PNG, JPG or WEBP using GD
- Images (PNG/JPG/WEBP) may be configured to scale up to any size
- Supports common customization requirements (size, color, text display, font size, background color, font for image rendering, or format-specific options such as guard bars or quiet zones)
Supported barcodes
| Format | Variations |
|---|---|
| Code 128 | Auto-Mode and forced A/B/C |
| EAN | EAN-2 / EAN-5 / EAN-8 / EAN-13 |
| UPC | UPC-A / UPC-E |
| MSI | Mod10, Mod11, Mod1010, Mod1110 |
| Codabar | |
| Code 11 | |
| Code 2 of 5 | |
| Code 2 of 5 Interleaved | |
| Code 39 | |
| Code 93 | |
| ITF-14 | |
| Pharmacode |
Installation
Install the package via composer:
composer require antwerpes/barcodes-1d
Usage
Use the Barcodes factory class to create an encoder and render its output to SVG or a base64-encoded image:
use Antwerpes\Barcodes\Barcodes; use Antwerpes\Barcodes\Enumerators\Format; // SVG $svg = Barcodes::create('12345678', Format::CODE_128); file_put_contents('img.svg', $svg); // Or as an image $image = Barcodes::create('12345678', Format::CODE_128, 'png'); file_put_contents('img.png', base64_decode($image)); // Example for scaled up (4x) WEBP $image = Barcodes::create('12345678', Format::CODE_128, 'webp', [ 'image_scale' => 4, ]); file_put_contents('img.webp', base64_decode($image));
Customization
Check out the options for an overview of all customization options.
Examples
Code 128
Barcodes::create('A12345', Format::CODE_128);
EAN-13
Barcodes::create('5901234123457', Format::EAN_13); Barcodes::create('5901234123457', Format::EAN_13, 'svg', ['flat' => true]); Barcodes::create('5901234123457', Format::EAN_13, 'svg', ['with_quiet_zone' => true]);
EAN-2 / EAN-5 / EAN-8
Barcodes::create('53', Format::EAN_2); Barcodes::create('52495', Format::EAN_5); Barcodes::create('96385074', Format::EAN_8);
UPC-A / UPC-E
Barcodes::create('123456789999', Format::UPC_A); Barcodes::create('01245714', Format::UPC_E); // These also work and will produce the same result Barcodes::create('124571', Format::UPC_E); Barcodes::create('01210000457', Format::UPC_E); Barcodes::create('012100004574', Format::UPC_E);
Codabar
Barcodes::create('A12345B', Format::CODABAR);
Code 11
Barcodes::create('01234-5678', Format::CODE_11);
Code 2 of 5 / Code 2 of 5 Interleaved / ITF-14
Barcodes::create('1234567', Format::CODE_25); Barcodes::create('12345670', Format::CODE_25_INTERLEAVED); Barcodes::create('98765432109213', Format::ITF_14);
Code 39 / Code 93
Barcodes::create('AB12', Format::CODE_39); Barcodes::create('TEST93', Format::CODE_93);
MSI
Barcodes::create('8052', Format::MSI);
Pharmacode
Barcodes::create('1234', Format::PHARMACODE);
Options
Generic options for all barcode formats:
| Option | Default | Type | Comment |
|---|---|---|---|
width |
2 |
int |
Width of a single bar |
height |
100 |
int |
Height of a regular bar |
text_margin |
2 |
int |
Distance between barcode and text |
text_align |
center |
string |
left / center / right |
background |
#ffffff |
string|null |
Background color. Use null for transparent background |
color |
#000000 |
string |
Color of the barcode and text |
text_color |
– | string |
Text color. Falls back to color if not set |
margin |
10 |
int |
Margin on all sides of the barcode |
margin_top |
– | int |
Falls back to margin if not set |
margin_right |
– | int |
Falls back to margin if not set |
margin_bottom |
– | int |
Falls back to margin if not set |
margin_left |
– | int |
Falls back to margin if not set |
display_value |
true |
bool |
Should the code text be displayed below the barcode? |
font_size |
20 |
int |
Large font sizes may break the layout |
image_font |
JetBrains Mono |
string |
Path to custom font TTF for image rendering (not used for SVG). |
image_scale |
1 |
int |
Sets the final image scale, e.g. 2x or 4x (not used for SVG). |
There are additional options for some barcode formats:
Code128
| Option | Default | Type | Comment |
|---|---|---|---|
mode |
AUTO |
string |
Encoding mode (AUTO / A/ B/ C). Use AUTO for most efficient encoding. |
EAN-8 / EAN-13 / UPC-A / UPC-E
| Option | Default | Type | Comment |
|---|---|---|---|
flat |
false |
bool |
Flat encoding (without the guard bars) |
with_quiet_zone |
false |
bool |
Enables quiet zones with (< and/or > symbols). Only relevant for EAN-8 / EAN-13 |
Code39
| Option | Default | Type | Comment |
|---|---|---|---|
enable_checksum |
false |
bool |
Calculate and append mod43 checksum |
full_ascii |
false |
bool |
Enable full ASCII mode |
Code39
| Option | Default | Type | Comment |
|---|---|---|---|
full_ascii |
false |
bool |
Enable full ASCII mode |
MSI
| Option | Default | Type | Comment |
|---|---|---|---|
check_digit |
null |
string|null |
MOD_10 / MOD_11 / MOD_1010 / MOD_1110 |
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
License
The MIT License (MIT). Please see License File for more information.
Acknowledgements
antwerpes/barcodes-1d 适用场景与选型建议
antwerpes/barcodes-1d 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 11.29k 次下载、GitHub Stars 达 25, 最近一次更新时间为 2022 年 06 月 29 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「barcodes」 「EAN13」 「upc」 「code128」 「antwerpes」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 antwerpes/barcodes-1d 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 antwerpes/barcodes-1d 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 antwerpes/barcodes-1d 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
PHP library to generate linear and bidimensional barcodes
TCPDF is a PHP class for generating PDF documents and barcodes.
FPDF Barcode support for EAN13, UPC-A, Code 39, Code 128
An easy to use, non-bloated, barcode generator in PHP. Creates SVG, PNG, JPG and HTML images from the most used 1D barcode standards.
Fork of Real GTIN Validator
A PHP class for EAN and ISBN name lookup and validation using the API on ean-search.org
统计信息
- 总下载量: 11.29k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 25
- 点击次数: 5
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2022-06-29
