Replace Image By Id
Replaces an existing image in a Google Slides presentation with a new image using the image object ID.
Common Properties
- Name - The custom name of the node.
- Color - The custom color of the node.
- Delay Before (sec) - Waits in seconds before executing the node.
- Delay After (sec) - Waits in seconds after executing node.
- Continue On Error - Automation will continue regardless of any error. The default value is false.
If the ContinueOnError property is true, no error is caught when the project is executed, even if a Catch node is used.
Inputs
- Presentation Id - The ID of the Google Slides presentation containing the image to replace.
- Image Object Id - The unique identifier of the image object to be replaced.
- Replacement Image Url - The URL of the new image that will replace the existing one.
Options
- Image Replace Method - The method used to fit the replacement image:
- Center Inside - Scales the image to fit entirely within the original image boundaries while maintaining aspect ratio
- Center Crop - Scales and crops the image to fill the original image boundaries while maintaining aspect ratio
How It Works
The Replace Image By Id node updates an existing image in a Google Slides presentation with a new image. When executed, the node:
- Validates the provided inputs (Presentation Id, Image Object Id, Replacement Image Url)
- Connects to the specified Google Slides presentation
- Locates the image object using the provided Image Object Id
- Replaces the existing image with the new image from the provided URL
- Applies the specified image fitting method
Requirements
- A valid Google Slides presentation ID
- Valid Google Slides API credentials
- A valid Image Object Id for the image to be replaced
- A publicly accessible URL for the replacement image
- Proper permissions to modify the presentation
Error Handling
The node will return specific errors in the following cases:
- Empty or invalid Presentation Id
- Empty or invalid Image Object Id
- Empty or invalid Replacement Image Url
- Google Slides API authentication errors
- Insufficient permissions to modify the presentation
- Invalid presentation ID
- Invalid image object ID
- Google Slides service errors
Usage Notes
- The Presentation Id can be found in the URL of the Google Slides presentation
- The Image Object Id can be obtained using the Get Presentation node with the "Return Element IDs" option
- The Replacement Image Url must be publicly accessible (not behind authentication)
- The Image Replace Method determines how the new image fits within the original image boundaries:
- Center Inside - Ensures the entire replacement image is visible but may leave empty space
- Center Crop - Fills the entire original image area but may crop parts of the replacement image
- The replaced image maintains its position and size on the slide
- This node is useful for updating images in templates or regularly updated presentations
- Supported image formats include JPG, PNG, GIF, and other web-friendly formats
Examples
Example 1: Replace a Single Image
Replace a specific image with a new one:
Presentation Id: "1ABC..."
Image Object Id: "image_001"
Replacement Image Url: "https://example.com/new-logo.png"
Image Replace Method: CENTER_INSIDE
Replaces the image while maintaining its position and size on the slide.
Example 2: Update Chart Image
Replace a chart image with an updated version:
Presentation Id: "1ABC..."
Image Object Id: "sales_chart_q4"
Replacement Image Url: "https://example.com/charts/sales-2024-q4-updated.png"
Image Replace Method: CENTER_CROP
Example 3: Replace Multiple Images in Sequence
Update several images in a presentation:
const imageUpdates = [
{ id: "logo_header", url: "https://example.com/new-header-logo.png" },
{ id: "product_image_1", url: "https://example.com/products/updated-1.jpg" },
{ id: "team_photo", url: "https://example.com/team/new-team-photo.jpg" }
];
for (const update of imageUpdates) {
msg.imageObjectId = update.id;
msg.replacementUrl = update.url;
// Use Replace Image By Id node here
}
Example 4: Replace with Different Replace Methods
// For logos and icons - use CENTER_INSIDE to show full image
msg.imageObjectId = "company_logo";
msg.replacementUrl = "https://example.com/logo-new.png";
msg.replaceMethod = "CENTER_INSIDE";
// Replace Image By Id node
// For background images - use CENTER_CROP to fill space
msg.imageObjectId = "background_img";
msg.replacementUrl = "https://example.com/backgrounds/new-bg.jpg";
msg.replaceMethod = "CENTER_CROP";
// Replace Image By Id node
How to Find Image Object IDs
To get the Image Object Id for images you want to replace:
- Use Get Presentation node with "Return Element IDs" enabled
- Specify the Page Object Id (slide ID)
- Parse the response to find image elements
- Extract the objectId from image elements
// After Get Presentation with Return Element IDs
const elements = msg.response;
const images = elements.filter(el => el.image);
// Log all image IDs
images.forEach(img => {
console.log(`Image ID: ${img.objectId}`);
});
// Find specific image by description or position
const headerImage = images.find(img =>
img.description && img.description.includes('header')
);
msg.imageObjectId = headerImage.objectId;
Tips for Effective Use
- ID Discovery: Use Get Presentation node to discover image object IDs before replacement
- Consistent IDs: When creating templates, use descriptive image IDs for easier automation
- URL Validation: Verify image URLs are accessible before running batch replacements
- Replace Method: Choose CENTER_INSIDE for logos/icons, CENTER_CROP for photos/backgrounds
- Aspect Ratios: Match replacement image aspect ratios to original for best results
- Batch Updates: Process multiple image replacements in a loop for efficiency
- Error Handling: Check if image object ID exists before attempting replacement
Common Use Cases
Use Case 1: Update Report Charts
Automatically update chart images in recurring reports:
// Generate new chart
const chartImage = await generateSalesChart(msg.currentMonthData);
const chartUrl = await uploadToCloudStorage(chartImage);
// Replace old chart in presentation
msg.presentationId = msg.monthlyReportId;
msg.imageObjectId = "monthly_sales_chart";
msg.replacementUrl = chartUrl;
// Use Replace Image By Id node
Use Case 2: Refresh Product Images
Update product images in a catalog presentation:
// Fetch latest product images from database
const products = await getProducts();
for (const product of products) {
msg.imageObjectId = `product_${product.id}`;
msg.replacementUrl = product.latestImageUrl;
// Replace Image By Id node
}
Use Case 3: Update Team Photos
Replace team member photos in an organizational presentation:
// Update team member photos
const teamMembers = [
{ id: "ceo_photo", newUrl: "https://example.com/photos/new-ceo.jpg" },
{ id: "cto_photo", newUrl: "https://example.com/photos/new-cto.jpg" }
];
for (const member of teamMembers) {
msg.imageObjectId = member.id;
msg.replacementUrl = member.newUrl;
msg.replaceMethod = "CENTER_CROP"; // Fill the frame
// Replace Image By Id node
}
Use Case 4: Seasonal Template Updates
Update seasonal images in marketing templates:
// Seasonal campaign - replace header images
const season = getCurrentSeason(); // "spring", "summer", "fall", "winter"
const seasonalImages = {
spring: "https://example.com/seasons/spring-banner.jpg",
summer: "https://example.com/seasons/summer-banner.jpg",
fall: "https://example.com/seasons/fall-banner.jpg",
winter: "https://example.com/seasons/winter-banner.jpg"
};
msg.imageObjectId = "seasonal_header";
msg.replacementUrl = seasonalImages[season];
msg.replaceMethod = "CENTER_CROP";
// Replace Image By Id node
Use Case 5: Dashboard Screenshot Updates
Replace dashboard screenshots with current data:
// Capture fresh dashboard screenshot
const screenshotUrl = await captureDashboardScreenshot();
// Replace old screenshot in presentation
msg.imageObjectId = "dashboard_screenshot_main";
msg.replacementUrl = screenshotUrl;
msg.replaceMethod = "CENTER_INSIDE";
// Replace Image By Id node
Difference from Replace Shapes With Image
Replace Image By Id vs Replace Shapes With Image:
| Replace Image By Id | Replace Shapes With Image |
|---|---|
| Replaces images by their object ID | Replaces shapes containing specific text |
| Requires knowing exact image ID | Searches for shapes by text content |
| More precise, targets specific images | Can replace multiple shapes at once |
| Better for known, fixed image positions | Better for template-based workflows |
| Use when you know which image to replace | Use when images are in placeholders with text |
Common Errors and Solutions
| Error | Cause | Solution |
|---|---|---|
| "Presentation ID cannot be empty" | No ID provided or ID is "_" | Ensure valid Presentation Id is provided |
| "Image Object ID cannot be empty" | No object ID provided | Provide valid image object ID from Get Presentation |
| "Replacement image URL cannot be empty" | No URL provided | Ensure valid publicly accessible image URL is provided |
| Invalid image object ID | Object ID doesn't exist or isn't an image | Use Get Presentation to find valid image object IDs |
| Image not found | Image object ID doesn't match any image | Verify object ID is correct; element might not be an image |
| Permission denied on URL | Image URL requires authentication | Use publicly accessible URLs or upload to cloud storage |
| Wrong element type | Object ID refers to shape, not image | Ensure the object ID is for an image element |
| Image appears distorted | Wrong replace method for aspect ratio | Try switching between CENTER_INSIDE and CENTER_CROP |
Best Practices
- ID Management: Keep a mapping of image IDs to their purposes in your documentation
- Verification: Use Get Presentation to verify image IDs before batch operations
- URL Testing: Test replacement URLs in a browser before automation
- Consistent Sizing: Size replacement images close to original dimensions for best results
- Error Recovery: Implement fallback logic for missing or failed image replacements
- Template Design: When creating templates, use descriptive image object IDs
- Aspect Ratios: Maintain consistent aspect ratios between original and replacement images
- Batch Processing: Group related image replacements for better workflow organization
Advanced Workflow Integration
Complete Image Update Workflow
// 1. Get presentation structure to find image IDs
msg.presentationId = "1ABC...";
// (Use Get Presentation with Return Element IDs)
// 2. Parse response to find images needing updates
const elements = msg.response;
const outdatedImages = elements.filter(el =>
el.image && needsUpdate(el.objectId)
);
// 3. Generate or fetch new images
const newImages = await fetchUpdatedImages();
// 4. Replace each outdated image
for (const oldImage of outdatedImages) {
const newImageUrl = newImages[oldImage.objectId];
msg.imageObjectId = oldImage.objectId;
msg.replacementUrl = newImageUrl;
msg.replaceMethod = determineReplaceMethod(oldImage);
// (Use Replace Image By Id node)
}
// 5. Verify replacements
// (Optional: Get Presentation again to confirm changes)
Conditional Image Replacement
// Only replace images that meet certain criteria
const presentation = msg.presentationMetadata;
for (const slide of presentation.slides) {
// Get elements for this slide
msg.pageObjectId = slide.objectId;
// (Use Get Presentation with Return Element IDs)
const images = msg.response.filter(el => el.image);
for (const img of images) {
// Check if image needs updating (e.g., based on timestamp or metadata)
if (shouldUpdateImage(img)) {
msg.imageObjectId = img.objectId;
msg.replacementUrl = getNewImageUrl(img);
// (Use Replace Image By Id node)
}
}
}