title: How to add image to google doc with text wrapping via Google Script
body: <p>I have an image saved in my Google drive called "logo.png".</p>
  
  <p>I want to add the image to a Google document so that it's in the top left corner <strong><em>and</em></strong> so that it does not distort the text around it. (In other words, I want the text to "wrap" around the image). </p>
  
  <p><strong>How do I add an image to a Google Doc using Google Script so that surrounding text wraps around the image?</strong></p>
  
  <p>My script so far:</p>
  
  <pre><code>function myFunction(e) {
  
    var t1 = 'Center for Success';
    var t2 = 'Foundational Hall';
    var t3 = 'Instruction Sheet for Testing Requirements';
  
    var boldRight ={};
      boldRight[DocumentApp.Attribute.BOLD]=true;
      boldRight[DocumentApp.Attribute.HORIZONTAL_ALIGNMENT]=DocumentApp.HorizontalAlignment.RIGHT;
  
    var boldCenterUnderline ={};
      boldCenterUnderline[DocumentApp.Attribute.BOLD]=true;
      boldCenterUnderline[DocumentApp.Attribute.UNDERLINE]=true;
      boldCenterUnderline[DocumentApp.Attribute.HORIZONTAL_ALIGNMENT]=DocumentApp.HorizontalAlignment.CENTER;
  
    var filename = 'fileTest';
  
    var doc = DocumentApp.create(filename);
    var body = doc.getBody();
  
    body.appendParagraph(t1).setAttributes(boldRight);
    body.appendParagraph(t2).setAttributes(boldRight); 
    body.appendParagraph(space); 
    body.appendParagraph(t3).setAttributes(boldCenterUnderline);
  
    doc.saveAndClose();
  
  }
  </code></pre>
  
  <p><strong>Desired Result</strong>:</p>
  
  <p><a href="https://i.stack.imgur.com/l7kFy.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/l7kFy.png" alt="enter image description here"></a></p>
  
  <p>I saw <a href="https://ctrlq.org/code/20078-insert-image-in-google-document" rel="nofollow noreferrer">here</a> that an image can be added in various ways, but neither approach has worked for me AND I do not see how I can control a wrapping attribute.</p>
  
  <h2> Update </h2>
  
  <p>I tried using the following code (with fake ID shown in URL), but it just created a blank document:</p>
  
  <pre><code>  var image  = "https://drive.google.com/open?id=2PJGK5C64HLKKoQIv52jGhUjjdiXU34Mp";
    var fileID = image.match(/[\w\_\-]{25,}/).toString();
    var blob   = DriveApp.getFileById(fileID).getBlob();
    body.appendImage(blob)
  </code></pre>