mirror of
https://github.com/zadam/trilium.git
synced 2025-11-07 13:56:11 +01:00
added image OCR and parsing text from PDF (and OCR of PDF images)
This commit is contained in:
@@ -65,24 +65,6 @@ function getImageMimeFromExtension(ext) {
|
||||
return `image/${ext === 'svg' ? 'svg+xml' : ext}`;
|
||||
}
|
||||
|
||||
function runOcr(note, buffer) {
|
||||
if (!optionService.getOptionBool('ocrImages')) {
|
||||
return;
|
||||
}
|
||||
|
||||
const start = Date.now();
|
||||
const img = new Canvas.Image();
|
||||
img.src = buffer;
|
||||
const canvas = new Canvas.createCanvas(img.width, img.height);
|
||||
const ctx = canvas.getContext('2d');
|
||||
ctx.drawImage(img, 0, 0, img.width, img.height);
|
||||
const plainText = OCRAD(canvas);
|
||||
|
||||
log.info(`OCR of ${buffer.byteLength} image bytes into ${plainText.length} chars of text took ${Date.now() - start}ms`);
|
||||
|
||||
note.saveNoteAttachment('plainText', 'text/plain', plainText);
|
||||
}
|
||||
|
||||
function updateImage(noteId, uploadBuffer, originalName) {
|
||||
log.info(`Updating image ${noteId}: ${originalName}`);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user