I need to insert images at a fixed width to keep organized on the sheet. I have been testing, just getting one image where I need it, and have so far failed.
My current version works sometimes; other times, it displays the image three times, some scaled and some not. I am struggling to troubleshoot because I don't fully understand what the code is doing.
I am hoping this is a ridiculously easy fix.
I started basic, just getting the image in:
function sized_image() {
var ss = SpreadsheetApp.getActive();
var img = ss.getRange('B3').getValue();
ss.insertImage(img,4,4).
}
That worked great. I feel like I am really close, but I can't seem to get it to resize the images. This is the current version of my code:
function sized_image() {
var ss = SpreadsheetApp.getActive();
var img = ss.getRange('B3').getValue();
var finalimg = ss.insertImage(img,6,6);
var orgW = finalimg.getWidth();
var orgH = finalimg.getHeight();
var tgtW = 500
var ratio = orgW / tgtW
var newH = orgH / ratio
ss.insertImage(img,4,4).setWidth(tgtW).setHeight(newH);
finalimg.setWidth(tgtW).setHeight(newH);
}
Note: I have ss.insertimage(img,4,4)
as a different image location for troubleshooting.
I realize this is a pretty basic code, and sadly, I only got here through a lot of googling and am now finding myself lost after adapting a few different solutions.
All images are Google Drive images, img
is the http://drive.google.com/uc?export=view&id=
link.