1

Why the below code return 'server error' in GSuite Spreadsheet?

function test() {
  var ss = SpreadsheetApp.openById('1Wc6nKxxxxxxxxxxxxxxxxxx0Ld6QyaY');
  var sheet = ss.getSheetByName('2018.0801-0831');
  var img = DriveApp.getFileById('1qw2uy3cNxxxxxxxxxxxxxxxxxDZRES');
  var imgBlob = img.getBlob();
  sheet.insertImage(imgBlob, 9, 20);
}

The Image is JPEG, 276KB. With an image its size is 173KB, this code is working. Is it possible to insert large imageBlobs?

Kentaro Usui
  • 23
  • 1
  • 4

1 Answers1

5

In my experience, when an image is inserted by insertImage(), the limitation is due to the image area (pixels^2) rather than the file size of it. The maximum area of image which can be inserted is 1,048,576 pixels^2.

I have experimented as follows.

  • Image with the following sizes can be inserted.
    • 1024 pixels x 1024 pixels
    • 2048 pixels x 512 pixels
    • 4096 pixels x 256 pixels
  • Image with the following sizes can NOT be inserted.
    • 1025 pixels x 1025 pixels
    • 1024 pixels x 1025 pixels
    • 1025 pixels x 1024 pixels

From these results, I concluded the limitation for inserting image is 1,048,576 pixels^2.

So if the area of image you want to insert is more than 1,048,576 pixels^2, please resize it and try again.

halfer
  • 19,824
  • 17
  • 99
  • 186
Tanaike
  • 181,128
  • 11
  • 97
  • 165
  • Thank you for advice. It was really helpful. Image cannot be inserted is 3972 x 360, so I will resize it. – Kentaro Usui Jul 10 '18 at 03:00
  • @Kentaro Usui I'm glad your issue was solved. Your question gave me a good chance to investigate the limitation. This is also useful for me. Thank you, too. – Tanaike Jul 10 '18 at 03:15