Introduction
Every day professionals, educators, and marketers rely on Google Docs and Google Slides to create rich, visual content. Often those files contain dozens of embedded images that later need to be reused, archived, or edited outside of the original document. Manually downloading each picture is time‑consuming and error‑prone, especially when dealing with large presentations or lengthy reports. Fortunately, Google’s scripting environment provides a straightforward way to extract every image in one go and store them as individual files in a chosen folder on Google Drive. In this article we will explore the reasons for bulk‑extracting images, prepare the destination folder, write a concise Apps Script that works for Docs, adapt it for Slides, and finally run the script to collect all assets automatically.
Why Extract Images from Google Workspace?
Extracting images programmatically offers several tangible benefits:
- Efficiency: One click replaces dozens of manual right‑click‑save actions.
- Consistency: All files are saved in the same format and resolution, preserving original quality.
- Organization: Images are automatically placed in a dedicated Drive folder, making future searches faster.
- Reusability: Once extracted, pictures can be repurposed for blogs, social media, or design projects without reopening the source document.
Understanding these advantages helps justify the short investment of setting up a simple script that will pay off many times over.
Preparing Your Google Drive Folder
Before running any script, create a folder that will hold the extracted images. This step keeps your Drive tidy and gives the script a clear target location.
- Open Google Drive and click New → Folder.
- Name the folder descriptively, e.g., Extracted_Images_ProjectX.
- Right‑click the folder and select Get link. Ensure the sharing setting is at least “Anyone with the link can view” so the script can write to it.
- Copy the folder’s ID from the URL (the string after
folders/).
We will paste this ID into the Apps Script so it knows exactly where to store each picture.
Using Google Apps Script for Google Docs
The core of the solution is a short Apps Script that scans a document, pulls every InlineImage, and saves it as a PNG or JPEG file. Follow these steps:
- Open the Google Doc you want to process.
- From the menu choose Extensions → Apps Script.
- Delete any starter code and paste the script below, replacing
YOUR_FOLDER_IDwith the ID you copied earlier.
Script (Docs):
- function extractImagesFromDoc() {
- var doc = DocumentApp.getActiveDocument();
- var body = doc.getBody();
- var folder = DriveApp.getFolderById(‘YOUR_FOLDER_ID’);
- var images = [];
- var total = 0;
- var search = body.getImages();
- search.forEach(function(img){
- var blob = img.getBlob();
- var name = ‘DocImg_’ + (++total) + ‘.’ + blob.getContentType().split(‘/’)[1];
- folder.createFile(blob.setName(name));
- });
- Logger.log(‘Extracted ‘ + total + ‘ images to folder ID: ‘ + folder.getId());
- }
Save the project, grant the requested permissions, and run extractImagesFromDoc. All embedded pictures will appear in the specified Drive folder, each named sequentially.
Adapting the Script for Google Slides
Google Slides stores images slightly differently, but the same Apps Script environment can handle them with minimal changes. Open a slide deck, launch Apps Script, and use the following version:
- function extractImagesFromSlides() {
- var presentation = SlidesApp.getActivePresentation();
- var slides = presentation.getSlides();
- var folder = DriveApp.getFolderById(‘YOUR_FOLDER_ID’);
- var count = 0;
- slides.forEach(function(slide){
- var images = slide.getImages();
- images.forEach(function(img){
- var blob = img.getBlob();
- var ext = blob.getContentType().split(‘/’)[1];
- var name = ‘SlideImg_’ + (++count) + ‘.’ + ext;
- folder.createFile(blob.setName(name));
-  >});
- });
- Logger.log(‘Extracted ‘ + count + ‘ images from Slides.’);
- }
Run the function, and the script will traverse every slide, pull each picture, and drop it into the same folder you prepared earlier. The naming convention distinguishes Doc images from Slide images, making post‑extraction management easier.
Running the Script and Managing Output
After you have both functions ready, you can execute them individually or create a master menu that offers both options from a single UI.
- In Apps Script, add a
onOpen()function that inserts a custom menu into Docs or Slides. - Use
SpreadsheetApp.getUi()(or the equivalent for Docs/Slides) to add “Extract Images” items linked to your functions. - When the menu item is clicked, the script runs in the background, and the Logs panel shows a quick summary of how many files were created.
- To verify, open the destination folder in Drive; you should see a series of files named
DocImg_1.png,SlideImg_3.jpg, etc. - If you need a different image format, modify
blob.getContentType()or useUtilities.convertBlob()before saving.
By keeping the folder ID in a single variable, you can reuse the same script across multiple documents, ensuring a consistent workflow for teams that regularly harvest visual assets.
Conclusion
Extracting every embedded picture from Google Docs or Google Slides no longer has to be a manual chore. By preparing a dedicated Drive folder, deploying a concise Apps Script, and tailoring the code for each file type, you can automate the entire process and keep your visual resources organized, high‑quality, and instantly accessible. The approach scales from single‑page reports to multi‑hundred‑slide decks, saving time and reducing the risk of missed images. Implement the scripts provided, customize the naming or format as needed, and you’ll have a reliable, repeatable solution that supports content repurposing, archiving, and collaborative design workflows across your organization.









