通过IMGAPP Google Sheet Library从图像链接中提取宽度和高度

发布于 2025-02-07 13:59:23 字数 176 浏览 1 评论 0 原文

我想从Google表中的URL中提取图像的尺寸。找到了这个库,可以正是我所追求的。

“ https://github.com/tanaikech/imgapp#getsize”场景和想知道我在脚本编辑器中应确切使用什么。如果我遵循以上内容,我将无法获得结果。

请帮忙。

谢谢

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

萌吟 2025-02-14 13:59:23

当我看到您提供的样品电子表格时,看来电子表格和脚本如下。

function myFunction() {

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

}

修改点:

  • 在这种情况下,您将 = myFunction(A2)的自定义函数放在单元格中。但是您的脚本没有检索值。
  • 在自定义函数上, driveapp.getFileById(fileID)由于限制而无法使用。
  • 您的脚本不会返回值。

当这些观点反映在实现您的目标的脚本中时,如下所示。

修改后的脚本:

请用以下脚本替换当前脚本并保存脚本。并且,请将 = myFunction(A2)的自定义函数放在单元格中。这样,返回宽度和高度。

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

测试:

当此修改后的脚本用于样品电子表格时,如下所示。

参考:

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:

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文