Skip to content

Instantly share code, notes, and snippets.

@richardharman
Forked from tagplus5/imageToText.gs
Created May 8, 2018 15:55
Show Gist options
  • Select an option

  • Save richardharman/4fdebb82cc54ab9adbee3dae7e94bc56 to your computer and use it in GitHub Desktop.

Select an option

Save richardharman/4fdebb82cc54ab9adbee3dae7e94bc56 to your computer and use it in GitHub Desktop.
google apps script image to text ocr
function doGet(request) {
if (request.parameters.url != undefined && request.parameters.url != "") {
var imageBlob = UrlFetchApp.fetch(request.parameters.url).getBlob();
var resource = {
title: imageBlob.getName(),
mimeType: imageBlob.getContentType()
};
var options = {
ocr: true
};
var docFile = Drive.Files.insert(resource, imageBlob, options);
var doc = DocumentApp.openById(docFile.id);
var text = doc.getBody().getText().replace("\n", "");
Drive.Files.remove(docFile.id);
return ContentService.createTextOutput(text);
}
else {
return ContentService.createTextOutput("request error");
}
}
@justahuman1
Copy link

Hello, I am having trouble executing this code. Anyway you could help me? Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment