antwerpes/barcodes-1d

用于编程创建和渲染条形码的库

1.4.1 2024-06-07 14:11 UTC

README

Logo

Packagist Code Style Downloads License

1D 条形码

PHP 编写的条形码生成器,用于将最常见的条形码格式编码和渲染到多种图像输出格式。

功能

  • 支持大多数常见条形码格式(Code128、EAN、UPC、...)
  • 可以使用 GD 渲染到 SVG、PNG、JPG 或 WEBP
  • 图像(PNG/JPG/WEBP)可以配置为放大到任意大小
  • 支持常见的定制需求(大小、颜色、文本显示、字体大小、背景颜色、图像渲染字体,或特定格式的选项,如保护条或静区)

支持的条形码

安装

通过 composer 安装此包

composer require antwerpes/barcodes-1d

用法

使用 Barcodes 工厂类创建编码器,并将其输出渲染为 SVG 或 base64 编码的图像

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));

定制

查看 选项 以了解所有定制选项的概述。

示例

Code 128

Code 128

Barcodes::create('A12345', Format::CODE_128);

EAN-13

EAN-13 EAN-13 Flat EAN-13 Quiet Zone

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

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

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

Codabar

Barcodes::create('A12345B', Format::CODABAR);

Code 11

Code 11

Barcodes::create('01234-5678', Format::CODE_11);

Code 2 of 5 / Code 2 of 5 Interleaved / ITF-14

Code 25 Code 25 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

Code 39 Code 93

Barcodes::create('AB12', Format::CODE_39);
Barcodes::create('TEST93', Format::CODE_93);

MSI

MSI

Barcodes::create('8052', Format::MSI);

Pharmacode

MSI

Barcodes::create('1234', Format::PHARMACODE);

选项

所有条形码格式的通用选项

某些条形码格式有附加选项

Code128

EAN-8 / EAN-13 / UPC-A / UPC-E

Code39

Code39

MSI

变更日志

请参阅 CHANGELOG 了解最近的变化信息。

贡献

请参阅 CONTRIBUTING 了解详细信息。

许可证

MIT 许可证(MIT)。请参阅 许可证文件 了解更多信息。

鸣谢