Images can quickly break the layout of a Google Doc.
If you’ve ever pasted screenshots, charts, or photos into a document, you’ve probably had to manually resize each one so it fits nicely on the page.
Good news: Google Apps Script can automate this completely.
In this post, you’ll learn how to use a simple Apps Script function to resize all images in a Google Doc to 50% of their current size—saving time and keeping your documents clean and consistent.
Why Automate Image Resizing?
Manually resizing images is:
- Time-consuming
- Inconsistent
- Easy to forget when working fast
Automating image resizing is useful when:
- Creating tutorials or documentation
- Working with lots of screenshots
- Cleaning up imported or copied content
- Preparing docs for printing or sharing
With Apps Script, you can fix this in seconds.
What This Script Does
This script:
- Loops through all inline images in the active Google Doc
- Reads each image’s current width and height
- Resizes the image to 50% smaller
- Preserves the original aspect ratio
It works safely and can be run multiple times.
The Apps Script Code
function resizeImagesToHalf() {
const doc = DocumentApp.getActiveDocument();
const body = doc.getBody();
const images = body.getImages();
images.forEach(image => {
const width = image.getWidth();
const height = image.getHeight();
image.setWidth(width * 0.5);
image.setHeight(height * 0.5);
});
}
How to Use the Script
- Open your Google Doc
- Click Extensions → Apps Script
- Paste the code into the editor
- Save the project
- Run
resizeImagesToHalf - Approve permissions (first run only)
Once it runs, every image in the document is resized instantly.
Adjusting the Resize Percentage
You’re not limited to 50%.
Just change the multiplier value:
| Desired Size | Multiplier |
|---|---|
| 75% | 0.75 |
| 60% | 0.6 |
| 40% | 0.4 |
Example (resize to 60%):
image.setWidth(width * 0.6);
image.setHeight(height * 0.6);
Important Notes
- This works on inline images only (the most common image type)
- It does not affect drawings or positioned images
- Each run resizes images based on their current size
- Safe to use in production documents
When This Is Especially Useful
- Cleaning up long technical documents
- Normalizing screenshots pasted from different sources
- Automating Docs workflows
- Teaching Apps Script automation examples
Final Thoughts
Google Apps Script is incredibly powerful for small automations like this.
What takes minutes (or hours) manually can be done in a single function call.
If you’re working with Google Docs regularly, small scripts like this can dramatically improve your workflow.