├── LICENSE
├── README.md
├── copyzpl.css
├── package.json
├── pako.js
├── zpl-image.html
└── zpl-image.js
/LICENSE:
--------------------------------------------------------------------------------
1 | zpl-image
2 |
3 | Copyright 2019 Mark Warren
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 |
2 | # zpl-image
3 |
4 | A pure javascript module that converts images to either Z64-encoded or ACS-encoded GRF bitmaps for use with ZPL.
5 | The term ACS (Alternative Compression Scheme) denotes the run-length compression algorithm described in the section
6 | of the ZPL Reference Manual titled "Alternative Data Compression Scheme". Z64 typically gives better compression
7 | but is not available on all printers (especially older ones). The ACS encoding should work on any printer made
8 | since the mid 90s, maybe earlier.
9 |
10 | This module provides the following features:
11 |
12 | - Works in both node.js and modern browsers.
13 | - Converts the image to grayscale, then applies a user-supplied blackness
14 | threshold to decide which pixels are black.
15 | - Optionally removes any empty/white space around the edges of the image.
16 | - Optionally rotates the image to one of the orthogonal angles. This step
17 | is often necessary as ZPL does not provide the ability to rotate an image
18 | during formatting.
19 | - Converts the monochrome image to a GRF bitmap.
20 | - Converts the GRF bitmap to either Z64 or ACS encoding.
21 | - For Z64, zlib in node.js or pako.js in the browser is used for compression.
22 |
23 | The blackness threshold is specified as an integer between 1 and 99 (think of it as a
24 | gray percentage). Pixels darker than the gray% are converted to black. The default is 50.
25 |
26 | Rotation is specified as one of the values:
27 |
28 | - `'N'` : No rotation, the default.
29 | - `'L'` : Left, 90 degrees counter-clockwise rotation.
30 | - `'R'` : Right, 90 degrees clockwise rotation.
31 | - `'I'` : Inverted, 180 degrees rotation.
32 | - `'B'` : Same as `'L'` but named to match the ZPL notation.
33 |
34 | Blackness and rotation are passed via an options object. For example, to specify
35 | a black threshold of 56% and rotation of -90 degrees, you would pass in:
36 |
37 | ```javascript
38 | { black:56, rotate:'L' }
39 | ```
40 |
41 | Trimming of empty space around the image is enabled by default. To disable, specify
42 | the option `notrim:true`.
43 |
44 | ## Demo
45 |
46 | Included with this module is the file `zpl-image.html`. You can run it directly
47 | from the browser using the `file://` scheme. It lets you drag and drop an image
48 | and then interactively adjust the blackness threshold and rotation.
49 |
50 | When you are satisfied with the results, select either Z64 or ACS encoding and
51 | click the clipboard icon to copy the ZPL. The ZPL will have the following format:
52 |
53 | ```
54 | ^FX filename.ext (WxHpx, X-Rotate, XX% Black)^FS
55 | ^GFA,grflen,grflen,rowlen,...ASCII-armored-encoding...
56 | ```
57 |
58 | `^FX ... ^FS` is a ZPL comment.
59 |
60 | `^GF` is the ZPL command for use-once image rendering (that is, the image is not
61 | saved to the printer for later recall by other label formats).
62 |
63 | The rendered image displayed on the page is the actual data decoded and then drawn
64 | to a canvas. If you are interested in that bit of functionality, look for `z64ToCanvas`
65 | and `acsToCanvas` in the `zpl-image.html` file.
66 |
67 | ## Generic Browser Usage
68 |
69 | To use in the browser, include the following two scripts:
70 |
71 | ```html
72 |
73 |
74 | ```
75 |
76 | There is a version of pako.js included with this module, but it will not be updated
77 | frequently. It is primarily intended for the demo html file but should be sufficient
78 | for production use.
79 |
80 | ```javascript
81 | // Works with and