3

I want to extract the dimensions of the image from the URL in google Sheet. Found this Library that does exactly what I am after.

https://github.com/tanaikech/ImgApp#getsize

But I am very new to this scenario and wondering what exactly I should use in the script editor. If I follow the above I can't get the results.

Please help.

Thanks

player0
  • 124,011
  • 12
  • 67
  • 124
  • 1
    First, I deeply apologize that my library was not useful for your situation. This is due to my poor skill. I deeply apologize for this again. I would like to study more. About `If I follow the above I can't get the results.`, I cannot understand it. This is due to my poor English skill. I deeply apologize for this. In order to correctly understand your current issue, can I ask you about the detail of it? – Tanaike Jun 14 '22 at 23:06
  • @Tanaike Please don't apologize. Your Image App Library is awesome. I just wish I get the same answers as your demo. This is the sample file. https://docs.google.com/spreadsheets/d/1dcqVH885CgRiXVSWgZ6abvayAc6_D7lW9vW9VQSm98s/edit?usp=sharing. I want to know what I should exactly add in the script editor. – Divya Ravishanker Jun 14 '22 at 23:23
  • Thank you for replying and providing more information. From your added information, I proposed a modified script as an answer. Could you please confirm it? If that was not useful, I apologize again. – Tanaike Jun 14 '22 at 23:48

1 Answers1

2

When I saw your provided sample Spreadsheet, it seems that the Spreadsheet and your script are as follows.

enter image description here

function myFunction() {

var blob = DriveApp.getFileById(fileId).getBlob();
var res = ImgApp.getSize(blob);
var width = res.width;
var height = res.height;

}

Modification points:

  • In this case, you put a custom function of =myFunction(A2) to a cell. But your script doesn't retrieve the value.
  • At the custom function, DriveApp.getFileById(fileId) cannot be used because of the limitation.
  • Your script doesn't return the values.

When these points are reflected in the script for achieving your goal, it becomes as follows.

Modified script:

Please replace your current script with the following script and save the script. And, please put a custom function of =myFunction(A2) to a cell. By this, the width and height are returned.

function myFunction(url) {
  const blob = UrlFetchApp.fetch(url).getBlob();
  const { width, height } = ImgApp.getSize(blob);
  return [[width, height]];
}

Testing:

When this modified script is used for your sample Spreadsheet, it becomes as follows.

enter image description here

References:

Tanaike
  • 181,128
  • 11
  • 97
  • 165