Field service jobs normally require collecting data and images as part of their scope. Image stamping in Google Drive is often necessary for compliance, audits, and accurate reporting. Photos often need to display timestamps, project IDs, or other identifiers to confirm authenticity. The problem is that traditional tools for stamping usually rely on third-party applications, which require uploading files to external servers and risk exposing sensitive data.
Our solution removes this concern by keeping everything within Google Workspace image stamping automation. Using only Drive, Sheets, Slides, Apps Script, and AppSheet, companies can stamp images automatically, maintain their original aspect ratio, and reduce file size without reducing resolution.
We’ll show how this secure Google Apps Script workflow for stamping images functions, and why it’s a better alternative to third-party tools.
The Problem: Why Traditional Image Stamping Fails Organizations
In many industries, images play a vital role in compliance, reporting, and operational workflows. You may need Google Workspace stamped images with dates to verify progress, an auditor may require evidence images with official marks, or an enterprise may store project documentation that must include identifiers for future reference.
In all these cases, stamping images in Google Drive is not optional; it is an operational necessity. The problem arises with the tools typically available for this task. Most stamping solutions depend on third-party applications. This means sensitive corporate files must be uploaded to external servers outside the organization’s control, creating security, privacy, and compliance concerns.
Beyond these risks, some tools might distort images by altering their aspect ratio, reducing visual quality, or even increasing file sizes unnecessarily. Companies need a method that keeps files secure, preserves integrity, and integrates seamlessly with their existing Google Workspace automation workflow.
The Technical Challenge: Preserving Aspect Ratio and Managing File Size
When organizations attempt to stamp images directly in Google Workspace, they quickly face two common but critical challenges: aspect ratio distortion and file size inflation. Aspect ratio distortion happens when an image is forced into a fixed-sized canvas, such as a standard Google Slides page for watermarking or stamping. Instead of fitting naturally, the image may stretch or compress, leading to visible deformation.
For industries where accuracy and authenticity matter, such as audits, compliance inspections, or construction progress reports, even minor distortions can compromise the credibility of the evidence. The second challenge is file size. Some tools reduce image dimensions to shrink storage requirements, but this sacrifices detail.
Others keep the resolution intact but add unnecessary metadata or use inefficient conversions, which results in large, storage-heavy files. Companies need a Google Apps Script image automation method that addresses both issues: stamping images without altering their aspect ratio and reducing file size without lowering resolution.
The Workaround: A Google Workspace-Only Solution
To overcome the challenges of aspect ratio distortion and oversized files, we developed a method that uses only Google Workspace tools for image stamping, with no third-party applications involved. The solution takes advantage of Google Drive, Sheets, Slides, and Apps Script, working together as a secure and automated system.
The process begins by reading each image’s metadata in Google Drive, which includes its width, height, and rotation. Instead of forcing the photo into a fixed slide layout, a temporary Google Slides presentation for stamping is created and dynamically resized to match the exact dimensions of the image. This ensures that the picture fits perfectly, preserving its original aspect ratio without stretching or compressing.
Next, the image is inserted into the slide, filling the background naturally. A text box is then placed on top, containing the required stamp information such as a timestamp, ID, or other identifiers. Once stamped, the slide is exported as a high-quality JPEG file.
During the export, the image is automatically compressed in Google Workspace, which reduces file size while keeping the original resolution intact. To maintain a clean workflow, the stamped file is saved back to Google Drive in a structured folder system, while the temporary Slide file is removed. At the same time, Google Sheets is updated with the new file path and completion status, ensuring every action is tracked.
This workaround allows companies to automatically stamp and optimize images in Google Workspace, eliminating the need for risky third-party tools.
Step- Stamping an Image with Text:
// Stamp text onto an image using a Google Slide
function stampImage(file, stampText, fileName, rowNumber) {
const presentationId = DocsServiceApp.createNewSlidesWithPageSize({
title: “TempSlide”,
width: { unit: “pixel”, size: 800 }, // Example size
height: { unit: “pixel”, size: 600 }
});
const slide = SlidesApp.openById(presentationId).getSlides()[0];
// Insert image into slide
slide.insertImage(file.getBlob());
// Wrap text to fit within 45% of image height
const fontSize = Math.max(7, Math.floor(600 * 0.03)); // Base font size
const maxBoxHeight = Math.floor(600 * 0.45); // 45% of height
const estCharWidth = fontSize * 0.55;
const charsPerLine = Math.floor((800 * 0.8) / estCharWidth); // 80% of width
// Simple word-wrap function
function wrapByChars(text, charsPerLine) {
const words = text.split(/\s+/);
const lines = [];
let cur = “”;
for (const w of words) {
if (!cur) cur = w;
else if ((cur.length + 1 + w.length) <= charsPerLine) cur += ” ” + w; else { lines.push(cur); cur = w; } } if (cur) lines.push(cur); return lines; } const wrappedLines = wrapByChars(stampText, charsPerLine); const lineHeight = Math.ceil(fontSize * 1.15); const boxHeight = wrappedLines.length * lineHeight + 6; // Add padding const maxLineWidth = Math.max(…wrappedLines.map(line => Math.ceil(line.length * estCharWidth))) + 20;
const boxWidth = Math.min(maxLineWidth, 800 * 0.8);
// Add text box
const textBox = slide.insertTextBox(wrappedLines.join(“\n”), 10, 10, boxWidth, boxHeight);
textBox.getText().getTextStyle().setFontSize(fontSize).setForegroundColor(‘#FFFFFF’);
textBox.getFill().setSolidFill(‘#000000’, 0.6); // Semi-transparent background
// Export as PNG
SlidesApp.openById(presentationId).saveAndClose();
const thumbnail = Slides.Presentations.Pages.getThumbnail(presentationId, slide.getObjectId(), {
‘thumbnailProperties.thumbnailSize’: ‘LARGE’,
‘thumbnailProperties.mimeType’: ‘PNG’
});
const resultBlob = UrlFetchApp.fetch(thumbnail.contentUrl).getBlob().setName(fileName);
// Clean up
DriveApp.getFileById(presentationId).setTrashed(true);
Logger.log(Row ${rowNumber}: Stamped image created);
return resultBlob;
}
Step- Handling Image Rotation:
// Get image dimensions with rotation adjustment
function getImageDimensionsWithRotation(file, rowNumber) {
const size = ImgApp.getSize(file.getBlob());
let rawWidth = Number(size.width);
let rawHeight = Number(size.height);
// Get rotation from Drive metadata
let rotation = 0;
try {
const meta = Drive.Files.get(file.getId(), { fields: “imageMediaMetadata” });
if (meta.imageMediaMetadata && typeof meta.imageMediaMetadata.rotation !== ‘undefined’) {
rotation = Number(meta.imageMediaMetadata.rotation) || 0;
}
Logger.log(Row ${rowNumber}: Rotation: ${rotation * 90} degrees);
} catch (e) {
Logger.log(Row ${rowNumber}: Failed to get metadata: ${e});
}
// Swap dimensions if rotated 90° or 270°
const rotatedOdd = (rotation % 2 === 1);
const displayWidth = rotatedOdd ? rawHeight : rawWidth;
const displayHeight = rotatedOdd ? rawWidth : rawHeight;
return { displayWidth, displayHeight, rotation };
}
Step- Scaling an Image (Downscaling):
// Resize image if long edge exceeds limit
function resizeImage(file, maxLongEdge, rowNumber) {
const size = ImgApp.getSize(file.getBlob());
let rawWidth = Number(size.width);
let rawHeight = Number(size.height);
const longEdge = Math.max(rawWidth, rawHeight);
let scale = 1;
let resizedBlob = file.getBlob();
if (longEdge > maxLongEdge) {
scale = maxLongEdge / longEdge;
const targetWidth = Math.round(rawWidth * scale);
try {
const result = ImgApp.doResize(file.getId(), targetWidth);
if (result && result.blob) {
resizedBlob = result.blob;
Logger.log(Row ${rowNumber}: Resized to ${result.resizedwidth}x${result.resizedheight});
}
} catch (e) {
Logger.log(Row ${rowNumber}: Resize failed: ${e});
}
}
return resizedBlob;
}
Step- Converting an Image to JPEG for Size Reduction:
// Convert image to JPEG and save to Drive
function convertToJpeg(stampedBlob, targetFolder, newFileName, rowNumber) {
const jpgBlob = stampedBlob.getAs(‘image/jpeg’); // Convert to JPEG
const jpgFileName = newFileName.replace(/.[^/.]+$/, “”) + “.jpg”;
// Save to target folder
const jpgFile = targetFolder.createFile(jpgBlob).setName(jpgFileName);
Logger.log(Row ${rowNumber}: Saved JPEG: ${jpgFileName});
return jpgFileName;
}
The Automation Workflow: How It All Comes Together
What makes this solution powerful is not just the stamping process itself, but the way it is automated end-to-end with Google Workspace image stamping. By combining Google Drive, Google Slides, and Google Apps Script automation, the entire workflow runs smoothly without manual effort.
It begins with a Google Sheet image stamping tracker that stores the file paths of images to be processed. Each row represents an image and its metadata, including the timestamp or ID that needs to appear in the stamp. The script reads these rows one by one, checks for valid paths, and looks for any files that still require stamping.
When an image is found, the script follows the workaround process: creating a correctly sized Google Slides for stamping, inserting the image, overlaying the stamp text, and exporting it as a compressed JPEG. The new file is then stored in a mirrored folder structure within Google Drive stamped images, keeping the same organization as the original files for easy navigation.
This means thousands of images can be processed in batches without interruption. Altogether, the workflow transforms what was once a manual, error-prone task into a secure, repeatable, and auditable Google Workspace stamping process with no third-party tools required.
Step- batches without interruption:
const startTime = new Date().getTime();
const MAX_RUNTIME = 4 * 60 * 1000; // 5 minutes
const sheet = SpreadsheetApp.openById(SHEET_ID).getSheetByName(”);
const properties = PropertiesService.getScriptProperties();
let lastRow = parseInt(properties.getProperty(‘lastRow’) || ‘1’, 10);
let data = sheet.getDataRange().getValues();
for (let i = lastRow; i < data.length; i++) { if (new Date().getTime() – startTime >= MAX_RUNTIME) {
Logger.log(Time limit reached. Saving progress at row ${i});
properties.setProperty(‘lastRow’, i.toString());
deleteProcessImagesTriggers();
ScriptApp.newTrigger(‘processImages’).timeBased().after(50 * 1000).create();
return;
}
Step- Inserting an Image into a Google Slide:
// Create a slide and insert an image
function insertImageIntoSlide(file, rowNumber) {
const size = ImgApp.getSize(file.getBlob());
const width = Number(size.width);
const height = Number(size.height);
// Create slide with image dimensions
const presentationId = DocsServiceApp.createNewSlidesWithPageSize({
title: “TempSlide”,
width: { unit: “pixel”, size: width },
height: { unit: “pixel”, size: height }
});
// Insert image
const slide = SlidesApp.openById(presentationId).getSlides()[0];
slide.insertImage(file.getBlob());
Logger.log(Row ${rowNumber}: Image inserted into slide ${presentationId});
return presentationId;
}
Key Benefits of a Google-Only Image Stamping Solution
Adopting this stamping and optimization workflow within Google Workspace offers several clear advantages for organizations handling sensitive data and large image libraries.
Security and Compliance
Because the entire process runs inside Google’s ecosystem, there is no need to upload images to third-party platforms. This ensures that confidential files remain protected under the organization’s existing Google Workspace security policies.
Accuracy and Consistency
The automation applies stamps uniformly across all images, eliminating human error. File names and stamp text follow the same rules every time, resulting in a clean, professional archive.
Optimized Storage
By converting images to compressed JPEGs, the solution reduces file size without affecting resolution. This helps companies manage Drive quotas efficiently while maintaining high-quality visuals.
Scalability and Reliability
The script is designed to handle thousands of files in batches, automatically resuming where it left off if time limits are reached. This makes the process scalable for large organizations.
Cost-Effective Automation
Since the tools are part of Google Workspace, there are no extra licensing or subscription costs, making it a sustainable long-term solution.
Practical Use Cases for This Automation
This image stamping and optimization workflow is versatile and can be applied across different industries.
Construction and Engineering
Automatically stamp inspection photos with location and date details, ensuring compliance and accountability.
Telecommunications
Add project IDs or cable references to field images, creating a reliable photo record for audits.
Healthcare
Securely stamp diagnostic or research images with metadata, keeping them organized without leaving the Google ecosystem.
Education and Research
Add watermarks or labels to visual content for publications or internal sharing, protecting academic integrity.
Corporate Documentation
Stamp training or project images with timestamps for version control and knowledge management.
By integrating directly with Google Workspace, this automation supports organizations that rely heavily on documentation, compliance, and secure data handling.