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:
parent
dce9c6d956
commit
b20ddff300
1 changed files with 16 additions and 20 deletions
|
@ -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;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue