1

I want to use imageToZ64() from zpl-image module

I have installed it using: npm install zpl-image

and then I import it: import './../../../node_modules/zpl-image';

but when I use the fucntion like this let res = imageToZ64(canvas); i'm getting : Uncaught (in promise) ReferenceError: imageToZ64 is not defined

I tried to import it like this: import { imageToZ64 } from './../../../node_modules/zpl-image/zpl-image';

but the problem is this function uses other functions from pako.js which is another js file in the zpl-image. my question is how to import the module in a way that I can be able to access all the functions?

2
  • const { imageToZ64 } = require("zpl-image"); Should do the work. Also reading about import-export will help in long run Commented Dec 23, 2019 at 13:58
  • thanks but now I'm getting this error as I expected : main.js:66 Uncaught (in promise) ReferenceError: pako is not defined at t (main.js:66) at imageToZ64 (main.js:66) at main.js:28 it can't acess pako.js file ! Commented Dec 23, 2019 at 17:35

1 Answer 1

1

I highly recommend you read the README here : zpl-image repo GitHub

In order to use this with Node.js :

const imageToZ64 = require("zpl-image").imageToZ64;

Or :

const { imageToZ64, rgbaToZ64 } = require("zpl-image");

If you are trying to use it in the browser read generic browser usage since you already installed it via npm there is a demo file in node_modules/zpl-image/zpl-image.html ,you can open it in the browser, read its content, and understand how the code works which is the purpose of the demo file.

Sign up to request clarification or add additional context in comments.

5 Comments

i've tried both but i'm still getting : main.js:66 Uncaught (in promise) ReferenceError: pako is not defined at t (main.js:66) at imageToZ64 (main.js:66) at main.js:28 it can't acess pako.js file !
OK , can you please edit your question and provide more information : code you have wrote , your project setup , and what are you trying to do, so i can investigate further on why you are getting this errors
i really can't figure out why you are getting this error since you didn't provide more informations , if you're trying to use zpl-image in the browser i already edited the answer .
I added the JS scripts references to my HTML page just to try and suddenly it works! I can access the functions from my controller now I don't know how this helped actually ! ,, Thanks WaLid !
You are welcome, please do not forget to mark this answer as Accepted

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.