Google-apps-script – How to insert a webp image into a document

google docsgoogle-apps-script

I am trying to insert a webp format image into a table in a document – however it's giving me an error. When I try with a jpg file, I am able to insert the image at the top of the file (I don't know how to insert inside the table – I have {image1} text in the position where I want to insert the image.)

My code is, which works fine:

  var product_image = UrlFetchApp.fetch("https://laz-img-cdn.alicdn.com/images/ims-web/TB1HKyxaMFY.1VjSZFqXXadbXXa.png").getBlob();
  body.replaceText('{image1}', "img");
  body.insertImage(0, product_image);

But when I change the URL to a webp image, it gives mean an invalid data error. For examples this code:

  var product_image = UrlFetchApp.fetch("https://my-test-11.slatic.net/original/ed9960ec66acc822e34fdeac570211e0.jpg_340x340q80.jpg_.webp").getBlob();

Best Answer

I don't think you can do this, see documentation:

contentType String The MIME type to convert to. For most blobs, 'application/pdf' is the only valid option. For images in BMP, GIF, JPEG, or PNG format, any of 'image/bmp', 'image/gif', 'image/jpeg', or 'image/png' are also valid.