kreativekorp / barcode
从单个PHP文件生成条形码。
This package is not auto-updated.
Last update: 2024-09-19 16:03:18 UTC
README
从单个PHP文件生成条形码。MIT许可证。
- 输出为PNG、GIF、JPEG或SVG。
- 生成UPC-A、UPC-E、EAN-13、EAN-8、Code 39、Code 93、Code 128、Codabar、ITF、QR码和数据矩阵。
直接作为PHP脚本使用GET或POST
barcode.php?f={format}&s={symbology}&d={data}&{options}
例如。
barcode.php?f=png&s=upc-e&d=06543217
barcode.php?f=svg&s=qr&d=HELLO%20WORLD&sf=8&ms=r&md=0.8
当使用此方法时,必须使用URL编码转义非字母数字字符,例如%26
表示&
,或%2F
表示?
。
或作为其他PHP脚本中的库使用
include 'barcode.php';
$generator = new barcode_generator();
/* Output directly to standard output. */
header("Content-Type: image/$format");
$generator->output_image($format, $symbology, $data, $options);
/* Create bitmap image and write to standard output. */
header('Content-Type: image/png');
$image = $generator->render_image($symbology, $data, $options);
imagepng($image);
imagedestroy($image);
/* Create bitmap image and write to file. */
$image = $generator->render_image($symbology, $data, $options);
imagepng($image, $filename);
imagedestroy($image);
/* Generate SVG markup and write to standard output. */
header('Content-Type: image/svg+xml');
$svg = $generator->render_svg($symbology, $data, $options);
echo $svg;
/* Generate SVG markup and write to file. */
$svg = $generator->render_svg($symbology, $data, $options);
file_put_contents($filename, $svg);
当使用此方法时,必须不使用URL编码。
选项
f
- 格式。以下之一
png
gif
jpeg
svg
s
- 符号(条形码类型)。以下之一
upc-a code-39 qr dmtx
upc-e code-39-ascii qr-l dmtx-s
ean-8 code-93 qr-m dmtx-r
ean-13 code-93-ascii qr-q gs1-dmtx
ean-13-pad code-128 qr-h gs1-dmtx-s
ean-13-nopad codabar gs1-dmtx-r
ean-128 itf
d
- 数据。对于UPC或EAN,使用*
表示缺失的数字。对于Codabar,使用ABCD
或ENT*
表示起始和停止字符。对于QR码,以Shift-JIS编码kanji模式。
w
- 图像宽度。覆盖sf
或sx
。
h
- 图像高度。覆盖sf
或sy
。
sf
- 缩放因子。线性条形码默认为1,矩阵条形码默认为4。
sx
- 水平缩放因子。覆盖sf
。
sy
- 垂直缩放因子。覆盖sf
。
p
- 填充。线性条形码默认为10,矩阵条形码默认为0。
pv
- 顶部和底部填充。默认为p
的值。
ph
- 左部和右部填充。默认为p
的值。
pt
- 顶部填充。默认为pv
的值。
pl
- 左部填充。默认为ph
的值。
pr
- 右部填充。默认为ph
的值。
pb
- 底部填充。默认为pv
的值。
bc
- 背景颜色,格式为#RRGGBB
。
cs
- 空白颜色,格式为#RRGGBB
。
cm
- 模块颜色,格式为#RRGGBB
。
tc
- 文本颜色,格式为#RRGGBB
。仅适用于线性条形码。
tf
- SVG输出的文本字体。默认为等宽字体。仅适用于线性条形码。
ts
- 文本大小。对于SVG输出,这是以点为单位,默认为10。对于PNG、GIF或JPEG输出,这是GD库内置字体编号(从1到5),默认为1。仅适用于线性条形码。
th
- 文本基线到底部模块的距离。默认为10。仅适用于线性条形码。
ms
- 模块形状。以下之一:s
为方形,r
为圆形,或x
为X形。默认为s
。仅适用于矩阵条形码。
md
- 模块密度。一个介于0和1之间的数字。默认为1。仅适用于矩阵条形码。
wq
- 静区单元宽度。默认为1。使用0以抑制静区。
wm
- 窄模块和空格宽度。默认为1。
ww
- 宽模块和空格宽度。仅适用于Code 39、Codabar和ITF。默认为3。
wn
- 字符之间的窄空格宽度。仅适用于Code 39和Codabar。默认为1。