Google脚本图片大小调整 [英] Google Script Image Resizing
问题描述
我正在尝试制作一个脚本,用于调整Google文档中的图片大小。我有什么是:
var imgs = currentDoc.getImages();
for(var i = 1; i< imgs.length; i ++)
{
cell = row.insertTableCell(1);
imgNew = imgs [i] .setWidth(365);
cell.insertImage(1,imgNew.getBlob());
}
图片被正确插入,但大小不会改变,无论我设置了什么宽度。由于图像进入一个单元格(宽度= 370),是否可以使图像占据宽度的100%并按比例缩放高度?如果没有,我可以处理手动设置像素的数量,但这不工作。任何想法? 正如仅供参考,您不需要调用getBlob()只要需要Blob,getBlob()就可以直接传入。
I'm trying to make a script that will resize the images in a google doc. What I have is:
var imgs = currentDoc.getImages();
for (var i = 1; i < imgs.length; i++)
{
cell = row.insertTableCell(1);
imgNew = imgs[i].setWidth(365);
cell.insertImage(1, imgNew.getBlob());
}
The image gets inserted correctly but the size does not change regardless of what I set the width to. Since the image is going into a cell (width=370), is it possible to just make the image take up 100% of the width and scale the height proportionally? If not I can deal with manually setting the number of pixels but that is not working either. Any ideas?
Just as an FYI, you don't need to call getBlob()... anything that has a getBlob() can be passed in directly wherever a Blob is needed.
这篇关于Google脚本图片大小调整的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!