u
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { createCanvas, loadImage } from 'canvas';
|
||||
import { optimizeImage } from 'wasm-image-optimization';
|
||||
|
||||
/**
|
||||
* Converts a PNG image buffer into Zebra ZPL II Graphic Field (^GFA) format.
|
||||
@@ -10,12 +10,8 @@ import { createCanvas, loadImage } from 'canvas';
|
||||
* @returns {Promise<string>} Full ZPL string ready to send to a Zebra printer.
|
||||
*/
|
||||
export async function pngToZpl(pngBuffer, quantity = 1) {
|
||||
const img = await loadImage(pngBuffer);
|
||||
const canvas = createCanvas(img.width, img.height);
|
||||
const ctx = canvas.getContext('2d');
|
||||
ctx.drawImage(img, 0, 0);
|
||||
const imgData = ctx.getImageData(0, 0, img.width, img.height);
|
||||
const { data, width: w, height: h } = imgData;
|
||||
const raw = await optimizeImage({ image: pngBuffer, format: 'raw' });
|
||||
const { width: w, height: h, data } = raw;
|
||||
|
||||
const bytesPerRow = Math.ceil(w / 8);
|
||||
const totalBytes = bytesPerRow * h;
|
||||
|
||||
Reference in New Issue
Block a user