Open adnanlah opened 5 months ago
Hey @adnanlah, back at it with the binary ballet, I see! Hope you're doing well.
Based on the error message you're receiving, it seems like the Uint8Array
you're passing to Image.load()
might contain null bytes, which are not allowed.
The Image.load()
method in the @node-escpos/core
library does support loading images from a Uint8Array
. The method signature for load
accepts a parameter that can be either a string or a Uint8Array
, as indicated by its type annotation url: string | Uint8Array
. This means you can pass a Uint8Array
containing image data directly to the load
method, in addition to passing a file path as a string.
static load(url: string | Uint8Array, type: ImageMimeType | null = null): Promise<Image>
You can find this in the packages/core/src/image.ts file.
However, the error message suggests that the Uint8Array
you're passing might contain null bytes, which are not allowed. You might want to check the data you're passing to Image.load()
to ensure it doesn't contain any null bytes.
If you're sure that your Uint8Array
doesn't contain any null bytes, it would be helpful if you could provide a bit more context or a more complete code sample. This would help in identifying any potential issues with how you're using the Image.load()
method or the @node-escpos/core
library.
I tried this method:
import base from 'base64-arraybuffer'
export const base64ToArrayBuffer = (base64: string): Uint8Array => {
const arrayBuffer = base.decode(base64)
return new Uint8Array(arrayBuffer)
}
and this method:
export const base64ToArrayBuffer = (base64: string): Uint8Array => {
const binaryString = atob(base64)
const bytes = new Uint8Array(binaryString.length)
for (let i = 0; i < binaryString.length; i++) {
bytes[i] = binaryString.charCodeAt(i)
}
return bytes
}
And still both methods gave me the same error.
Hello,
I tried to load an image from a base64 data this way:
but I get this error: