u
This commit is contained in:
@@ -56,21 +56,13 @@ function getProjectRoot() {
|
||||
? JSON.parse(fs.readFileSync(nativeMapFile, 'utf8'))
|
||||
: {};
|
||||
|
||||
// Redirect native .node loading to distDir and preload libvips from distDir if present
|
||||
// Redirect native .node loading to distDir if present
|
||||
const origDlopen = process.dlopen;
|
||||
process.dlopen = function (mod, filename, flags) {
|
||||
const relFromRuntime = path.relative(runtimeDir, filename);
|
||||
const mappedName = nativeNodes[relFromRuntime] || path.basename(filename);
|
||||
const distCandidate = path.join(distDir, mappedName);
|
||||
const target = fs.existsSync(distCandidate) ? distCandidate : filename;
|
||||
if (mappedName.startsWith('sharp-')) {
|
||||
const vipsPath = path.join(distDir, 'libvips-cpp.so.8.18.7');
|
||||
if (fs.existsSync(vipsPath)) {
|
||||
try {
|
||||
origDlopen.call(process, { exports: {} }, vipsPath, os.constants.dlopen.RTLD_NOW | os.constants.dlopen.RTLD_GLOBAL);
|
||||
} catch {}
|
||||
}
|
||||
}
|
||||
return flags !== undefined ? origDlopen.call(process, mod, target, flags) : origDlopen.call(process, mod, target);
|
||||
};
|
||||
|
||||
|
||||
@@ -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