A fully automated workflow combining n8n, a Google Cloud Function, and OpenAI to optimize Shopify product images, generate SEO-friendly alt text, update Google Sheets, and replace images in your Shopify store.
- Extract: Fetch all product images from Shopify via an n8n workflow.
- Optimize: Send each image to a GCP Cloud Function that uses
sharpto convert and compress images to WebP. - Upload: Store optimized images in a Google Cloud Storage (GCS) bucket.
- Alt Text: Generate concise alt text using OpenAI for accessibility and SEO.
- Google Sheets: Log and track original and optimized image URLs along with generated alt text.
- Shopify Update: Replace old product images in Shopify with optimized versions and clean up originals.
shopify-images-optimizer/
βββ GCPCloudFunction/ # Cloud Function source code
β βββ index.js # HTTP-triggered image optimizer
β βββ package.json # dependencies and scripts
β βββ readme.md # Cloud Function-specific instructions
βββ GoogleSheets/ # Google Sheets template file
β βββ n8n-shopify-product-image-optimizer.xlsx
βββ n8n/ # n8n workflow definition
βββ n8n-shopify-image-optimizer.json
- Node.js v22+ and npm
- Google Cloud project with:
- Cloud Functions API enabled
- Cloud Storage bucket for optimized images
- Service account JSON key with Storage Object Admin role
- n8n instance (desktop, cloud, or self-hosted)
- Shopify Admin API access token
- OpenAI API key
- Google Sheets OAuth2 credentials
cd GCPCloudFunction
npm install
# For local testing
export BUCKET_NAME=<your-gcs-bucket>
export GOOGLE_APPLICATION_CREDENTIALS=<path-to-service-account.json>
npm startTo deploy via gcloud:
gcloud functions deploy optimizeImage \
--runtime nodejs22 \
--trigger-http \
--allow-unauthenticated \
--set-env-vars BUCKET_NAME=<your-gcs-bucket> \
--service-account <your-service-account>@<project>.iam.gserviceaccount.comTake note of the function URL (e.g., https://REGION-PROJECT.cloudfunctions.net/optimizeImage).
- Make a copy of
GoogleSheets/n8n-shopify-product-image-optimizer.xlsxin your Google Drive. - Share it with your n8n Google Sheets OAuth2 service account.
- Note the Spreadsheet ID and Sheet GID or just click on the node in n8n to select the sheet.
- Open your n8n editor and Import
n8n/n8n-shopify-image-optimizer.json. - Set up the following credentials in n8n:
- Shopify Access Token
- OpenAI API Key
- Google Sheets OAuth2
- Under Workflow Settings or the first HTTP Request node, set the following environment variables:
CLOUD_FUNCTION_URLβ the URL of your deployed optimizeImage functionSHOPIFY_STORE_IDβ your Shopify store subdomain
- Manual Trigger: Run the workflow on-demand via the manual trigger node in n8n.
- Scheduling: Use n8nβs Cron or schedule node to run periodically.
Upon execution, the workflow will:
- Retrieve all products from Shopify.
- Loop through each image, check if itβs already optimized in Google Sheets.
- Download and optimize via the GCP Function if needed.
- Generate alt text with OpenAI.
- Upload optimized images to GCS and update Google Sheets.
- Replace the original image in Shopify and remove the old one.
- n8n Executions: Monitor successful and failed executions in the n8n dashboard.
- Cloud Function Logs: View logs via Google Cloud Console under Cloud Functions > Logs.
- Google Sheets: Check the Google Sheets for a log of processed images, alt text, and URLs.
- Adjust
sharpsettings inGCPCloudFunction/index.jsto change quality or output format. - Modify alt-text prompts in the OpenAI node within the n8n workflow.
- Add resizing or watermark steps by extending the n8n image editing nodes.