Skip to content

Commit

Permalink
Merge pull request #18136 from calixteman/ml_stamp
Browse files Browse the repository at this point in the history
[Editor] Pass a buffer instead of a blob url to the ML api
  • Loading branch information
calixteman authored May 21, 2024
2 parents 6860288 + b20ddff commit 5da2894
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 5da2894

Please sign in to comment.