Skip to content

Commit

Permalink
[Editor] Pass a buffer instead of a blob url to the ML api
Browse files Browse the repository at this point in the history
  • Loading branch information
calixteman committed May 21, 2024
1 parent dce9c6d commit b20ddff
Showing 1 changed file with 16 additions and 20 deletions.
36 changes: 16 additions & 20 deletions src/display/editor/stamp.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit b20ddff

Please sign in to comment.