Skip to content

Instantly share code, notes, and snippets.

@Novack
Forked from tagplus5/imageToText.gs
Created January 15, 2019 20:25
Show Gist options
  • Select an option

  • Save Novack/1c89129647d228ce9faf4490f68e80a6 to your computer and use it in GitHub Desktop.

Select an option

Save Novack/1c89129647d228ce9faf4490f68e80a6 to your computer and use it in GitHub Desktop.

Revisions

  1. @tagplus5 tagplus5 renamed this gist Dec 18, 2015. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  2. @tagplus5 tagplus5 created this gist Dec 18, 2015.
    20 changes: 20 additions & 0 deletions ImageToText.gs
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,20 @@
    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");
    }
    }