-
Notifications
You must be signed in to change notification settings - Fork 17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
changelog #57
Comments
|
yes we can add a breaking changes, i will edit the release notes,
|
how can I load an image in the browser? |
try someting like this (need refactor) import { ImageData, Manager } from 'escpos-buffer';
export class ImageManager extends Manager {
async function toBase64(url) {
return new Promise((resolve, reject) => {
const reader = new FileReader();
reader.readAsDataURL(url);
reader.onload = () => resolve(reader.result);
reader.onerror = error => reject(error);
});
}
async function getImageDataFromBase64(base64Data) {
return new Promise((resolve, reject) => {
const img = new Image();
img.onload = function () {
const canvas = document.getElementById("secondaryCanvas");
const ctx = canvas.getContext("2d");
ctx.drawImage(img, 0, 0);
resolve(ctx.getImageData(0, 0, 256, 256));
}
img.src = base64Data;
});
}
async loadImage(filename: string): Promise<ImageData> {
return this.loadImageFromBuffer(Buffer.from(await this.toBase64(filename), 'base64'));
}
async loadImageFromBuffer(data: Buffer): Promise<ImageData> {
const image = await this.getImageDataFromBase64(data.toBuffer('base64'))
return {
width: image.info.width,
height: image.info.height,
data: image.data,
};
}
async buildQrcodeImage(data: string, size: number): Promise<ImageData> {
const buffer = await QRCode.toBuffer(data, { scale: size });
return this.loadImageFromBuffer(buffer);
}
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
can we add a changelog?
what are the breaking changes to v4 ?
The text was updated successfully, but these errors were encountered: