zpl_render 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +19 -1
- data/README.md +6 -0
- data/exe/zpl_render +3 -2
- data/lib/zpl_render/version.rb +1 -1
- data/lib/zpl_render.rb +36 -8
- metadata +5 -5
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 35e8a77278d37facd472debd3fbf7183523bd2f6405d63e164a1e8082e1c3a8e
|
|
4
|
+
data.tar.gz: 1d4dc9f4bc62465b679dfe571d5ad0cc07014e0f29ce2efe4ea5527983c3e134
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 35f48bba0d33863848b0296d4a3add758d8e8882f931bec640c55eef956a729ee8834ef327301b1b377134fd90c0d25f3e15d29df064446aef583d50c19e6eca
|
|
7
|
+
data.tar.gz: '09bd166c9440ff3cbfe1c0abb21a0583e494fd741eafd7e4db18cd5de3a44d84ec29b0c8d9598574fb6426db9672e5c5090f6364f7f6527e15e44c19dd8a1814'
|
data/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,23 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [0.2.0] - 2026-07-31
|
|
11
|
+
|
|
12
|
+
### Added
|
|
13
|
+
|
|
14
|
+
- Base64-encoded ZPL input: pass `base64: true` to `render` / `to_png` /
|
|
15
|
+
`to_pngs` / `to_pdf` (CLI: `--base64`) to decode the payload before
|
|
16
|
+
rendering, for labels stored base64-encoded in databases or WMS
|
|
17
|
+
exports. Accepts standard and URL-safe alphabets, tolerates
|
|
18
|
+
whitespace/newlines and missing padding, and raises `ZplRender::Error`
|
|
19
|
+
for invalid input. `ZplRender.decode_base64` is public for recovering
|
|
20
|
+
the raw `.zpl`.
|
|
21
|
+
|
|
22
|
+
### Fixed
|
|
23
|
+
|
|
24
|
+
- The release workflow's rubygems.org publish step is idempotent: it
|
|
25
|
+
skips when the version already exists instead of failing.
|
|
26
|
+
|
|
10
27
|
## [0.1.0] - 2026-07-31
|
|
11
28
|
|
|
12
29
|
Initial release.
|
|
@@ -45,5 +62,6 @@ Initial release.
|
|
|
45
62
|
- CI matrix for Ruby 3.0-3.4 (GitHub Actions and GitLab CI) with real
|
|
46
63
|
scanner round-trip verification.
|
|
47
64
|
|
|
48
|
-
[Unreleased]: https://github.com/wqsaali/zpl_render/compare/v0.
|
|
65
|
+
[Unreleased]: https://github.com/wqsaali/zpl_render/compare/v0.2.0...HEAD
|
|
66
|
+
[0.2.0]: https://github.com/wqsaali/zpl_render/compare/v0.1.0...v0.2.0
|
|
49
67
|
[0.1.0]: https://github.com/wqsaali/zpl_render/releases/tag/v0.1.0
|
data/README.md
CHANGED
|
@@ -42,6 +42,11 @@ ZplRender.to_png(zpl, warnings: warnings)
|
|
|
42
42
|
|
|
43
43
|
# Strict mode: raise on the first problem instead of warning
|
|
44
44
|
ZplRender.to_png(zpl, strict: true)
|
|
45
|
+
|
|
46
|
+
# Base64-encoded ZPL (e.g. from a database column or WMS export):
|
|
47
|
+
# decoded automatically before rendering
|
|
48
|
+
ZplRender.to_png(b64_payload, base64: true)
|
|
49
|
+
zpl = ZplRender.decode_base64(b64_payload) # or recover the raw .zpl
|
|
45
50
|
```
|
|
46
51
|
|
|
47
52
|
## Errors
|
|
@@ -61,6 +66,7 @@ silently drop label content.
|
|
|
61
66
|
zpl_render label.zpl -o label.png # PNG at 203 dpi, 4x6"
|
|
62
67
|
zpl_render label.zpl -o label.pdf -d 12 # PDF at 300 dpi
|
|
63
68
|
cat label.zpl | zpl_render -o out.png -W 4 -H 2
|
|
69
|
+
zpl_render --base64 label.b64 -o label.png # Base64-encoded ZPL input
|
|
64
70
|
```
|
|
65
71
|
|
|
66
72
|
## Barcode accuracy
|
data/exe/zpl_render
CHANGED
|
@@ -20,6 +20,7 @@ parser = OptionParser.new do |opts|
|
|
|
20
20
|
opts.on("-H", "--height INCHES", Float, "Label height in inches (default 6)") { |v| options[:height] = v }
|
|
21
21
|
opts.on("-s", "--scale N", Integer, "Integer upscale for PNG output (default 1)") { |v| options[:scale] = v }
|
|
22
22
|
opts.on("--strict", "Fail on the first problem instead of warning") { options[:strict] = true }
|
|
23
|
+
opts.on("-b", "--base64", "Input is Base64-encoded ZPL") { options[:base64] = true }
|
|
23
24
|
opts.on("-q", "--quiet", "Suppress warnings") { options[:quiet] = true }
|
|
24
25
|
opts.on("-v", "--version", "Print version") do
|
|
25
26
|
puts ZplRender::VERSION
|
|
@@ -41,11 +42,11 @@ begin
|
|
|
41
42
|
bytes = if File.extname(output).casecmp(".pdf").zero?
|
|
42
43
|
ZplRender.to_pdf(zpl, dpmm: options[:dpmm], width_in: options[:width],
|
|
43
44
|
height_in: options[:height], strict: options[:strict],
|
|
44
|
-
warnings: warnings)
|
|
45
|
+
base64: options[:base64], warnings: warnings)
|
|
45
46
|
else
|
|
46
47
|
ZplRender.to_png(zpl, dpmm: options[:dpmm], width_in: options[:width],
|
|
47
48
|
height_in: options[:height], scale: options[:scale],
|
|
48
|
-
strict: options[:strict], warnings: warnings)
|
|
49
|
+
strict: options[:strict], base64: options[:base64], warnings: warnings)
|
|
49
50
|
end
|
|
50
51
|
rescue ZplRender::Error => e
|
|
51
52
|
warn "error: #{e.message}"
|
data/lib/zpl_render/version.rb
CHANGED
data/lib/zpl_render.rb
CHANGED
|
@@ -34,36 +34,64 @@ module ZplRender
|
|
|
34
34
|
|
|
35
35
|
module_function
|
|
36
36
|
|
|
37
|
+
# Decode a Base64-encoded ZPL payload into the ZPL string. Accepts the
|
|
38
|
+
# standard and URL-safe alphabets, tolerates whitespace/newlines and
|
|
39
|
+
# missing padding, and raises ZplRender::Error when the input is not
|
|
40
|
+
# base64 or does not decode to ZPL. Useful when labels are stored
|
|
41
|
+
# base64-encoded (WMS exports, database columns, API payloads).
|
|
42
|
+
def decode_base64(data)
|
|
43
|
+
raise Error, "base64 input must be a String (got #{data.class})" unless data.respond_to?(:to_str)
|
|
44
|
+
|
|
45
|
+
compact = data.to_str.gsub(/\s+/, "").tr("-_", "+/")
|
|
46
|
+
compact += "=" * ((4 - compact.length % 4) % 4)
|
|
47
|
+
unless !compact.empty? && compact.match?(%r{\A[A-Za-z0-9+/]+={0,2}\z}) && (compact.length % 4).zero?
|
|
48
|
+
raise Error, "input is not valid base64"
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
zpl = begin
|
|
52
|
+
compact.unpack1("m0")
|
|
53
|
+
rescue ArgumentError => e
|
|
54
|
+
raise Error, "input is not valid base64: #{e.message}"
|
|
55
|
+
end
|
|
56
|
+
zpl.force_encoding(Encoding::UTF_8)
|
|
57
|
+
zpl.force_encoding(Encoding::BINARY) unless zpl.valid_encoding?
|
|
58
|
+
raise Error, "decoded base64 does not contain any ZPL commands" unless zpl.match?(/[\^~]/)
|
|
59
|
+
|
|
60
|
+
zpl
|
|
61
|
+
end
|
|
62
|
+
|
|
37
63
|
# Render every ^XA..^XZ format to a Canvas (dot matrix).
|
|
38
|
-
|
|
64
|
+
# Pass base64: true when +zpl+ is a Base64-encoded ZPL payload.
|
|
65
|
+
def render(zpl, dpmm: 8, width_in: 4.0, height_in: 6.0, strict: false, base64: false, warnings: nil)
|
|
39
66
|
raise Error, "zpl must be a String (got #{zpl.class})" unless zpl.respond_to?(:to_str)
|
|
40
67
|
|
|
68
|
+
zpl = base64 ? decode_base64(zpl) : zpl.to_str
|
|
41
69
|
renderer = Renderer.new(dpmm: dpmm, width_in: width_in, height_in: height_in, strict: strict)
|
|
42
|
-
labels = renderer.render(zpl
|
|
70
|
+
labels = renderer.render(zpl)
|
|
43
71
|
warnings.concat(renderer.warnings) if warnings
|
|
44
72
|
labels
|
|
45
73
|
end
|
|
46
74
|
|
|
47
75
|
# PNG bytes for the first label.
|
|
48
|
-
def to_png(zpl, dpmm: 8, width_in: 4.0, height_in: 6.0, scale: 1, strict: false, warnings: nil)
|
|
76
|
+
def to_png(zpl, dpmm: 8, width_in: 4.0, height_in: 6.0, scale: 1, strict: false, base64: false, warnings: nil)
|
|
49
77
|
labels = render(zpl, dpmm: dpmm, width_in: width_in, height_in: height_in,
|
|
50
|
-
strict: strict, warnings: warnings)
|
|
78
|
+
strict: strict, base64: base64, warnings: warnings)
|
|
51
79
|
raise Error, "no ^XA..^XZ label formats found" if labels.empty?
|
|
52
80
|
|
|
53
81
|
Output::Png.encode(labels.first, scale: scale)
|
|
54
82
|
end
|
|
55
83
|
|
|
56
84
|
# PNG bytes for every label.
|
|
57
|
-
def to_pngs(zpl, dpmm: 8, width_in: 4.0, height_in: 6.0, scale: 1, strict: false, warnings: nil)
|
|
85
|
+
def to_pngs(zpl, dpmm: 8, width_in: 4.0, height_in: 6.0, scale: 1, strict: false, base64: false, warnings: nil)
|
|
58
86
|
render(zpl, dpmm: dpmm, width_in: width_in, height_in: height_in,
|
|
59
|
-
strict: strict, warnings: warnings)
|
|
87
|
+
strict: strict, base64: base64, warnings: warnings)
|
|
60
88
|
.map { |canvas| Output::Png.encode(canvas, scale: scale) }
|
|
61
89
|
end
|
|
62
90
|
|
|
63
91
|
# PDF bytes, one page per label, at exact physical size.
|
|
64
|
-
def to_pdf(zpl, dpmm: 8, width_in: 4.0, height_in: 6.0, strict: false, warnings: nil)
|
|
92
|
+
def to_pdf(zpl, dpmm: 8, width_in: 4.0, height_in: 6.0, strict: false, base64: false, warnings: nil)
|
|
65
93
|
labels = render(zpl, dpmm: dpmm, width_in: width_in, height_in: height_in,
|
|
66
|
-
strict: strict, warnings: warnings)
|
|
94
|
+
strict: strict, base64: base64, warnings: warnings)
|
|
67
95
|
raise Error, "no ^XA..^XZ label formats found" if labels.empty?
|
|
68
96
|
|
|
69
97
|
Output::Pdf.encode(labels, dpmm: dpmm)
|
metadata
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: zpl_render
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.2.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Waqas Ali
|
|
8
|
-
autorequire:
|
|
8
|
+
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
11
|
date: 2026-07-31 00:00:00.000000000 Z
|
|
@@ -105,7 +105,7 @@ metadata:
|
|
|
105
105
|
source_code_uri: https://github.com/wqsaali/zpl_render
|
|
106
106
|
bug_tracker_uri: https://github.com/wqsaali/zpl_render/issues
|
|
107
107
|
changelog_uri: https://github.com/wqsaali/zpl_render/blob/main/CHANGELOG.md
|
|
108
|
-
post_install_message:
|
|
108
|
+
post_install_message:
|
|
109
109
|
rdoc_options: []
|
|
110
110
|
require_paths:
|
|
111
111
|
- lib
|
|
@@ -120,8 +120,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
120
120
|
- !ruby/object:Gem::Version
|
|
121
121
|
version: '0'
|
|
122
122
|
requirements: []
|
|
123
|
-
rubygems_version: 3.4.
|
|
124
|
-
signing_key:
|
|
123
|
+
rubygems_version: 3.4.19
|
|
124
|
+
signing_key:
|
|
125
125
|
specification_version: 4
|
|
126
126
|
summary: Render ZPL II label programs to PNG and PDF, with scanner-accurate barcodes.
|
|
127
127
|
test_files: []
|