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

Merge pull request #18136 from calixteman/ml_stamp

[Editor] Pass a buffer instead of a blob url to the ML api
This commit is contained in:
calixteman 2024-05-21 18:24:26 +02:00 committed by GitHub
commit 5da2894278
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

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;