Today I will show you a Google Apps Script that resizes all images from a Google document up to 16 cm.
Create a new document add some images, and from the main menu select the script editor and add this script with your google_document_id and the size of the images in cm.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | function resizeImagesInGoogleDoc() { // Replace this with the ID of your Google Docs document var docId = "google_document_id"; var doc = DocumentApp.openById(docId); var body = doc.getBody(); var images = body.getImages(); for (var i = 0; i < images.length; i++) { var image = images[i]; var width = image.getWidth(); var height = image.getHeight(); var ratio = height / width; var newWidthInCm = 16.0; // Set the new width of the image in centimeters var newWidthInPixels = Math.round(newWidthInCm * 28.3465); // Convert centimeters to pixels using the DPI of Google Docs image.setWidth(newWidthInPixels); image.setHeight(Math.round(newWidthInPixels * ratio)); } } |