1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-22 16:18:08 +02:00

[Editor] Pass a buffer instead of a blob url to the ML api

This commit is contained in:
Calixte Denizet 2024-05-21 17:07:03 +02:00
parent dce9c6d956
commit b20ddff300

View file

@ -441,26 +441,22 @@ class StampEditor extends AnnotationEditor {
width,
height
);
offscreen.convertToBlob().then(blob => {
const fileReader = new FileReader();
fileReader.onload = () => {
const url = fileReader.result;
this._uiManager
.mlGuess({
service: "image-to-text",
request: {
imageData: url,
},
})
.then(response => {
const altText = response?.output || "";
if (this.parent && altText && !this.hasAltText()) {
this.altTextData = { altText, decorative: false };
}
});
};
fileReader.readAsDataURL(blob);
});
this._uiManager
.mlGuess({
service: "image-to-text",
request: {
data: ctx.getImageData(0, 0, width, height).data,
width,
height,
channels: 4,
},
})
.then(response => {
const altText = response?.output || "";
if (this.parent && altText && !this.hasAltText()) {
this.altTextData = { altText, decorative: false };
}
});
}
const ctx = canvas.getContext("2d");
ctx.filter = this._uiManager.hcmFilter;