ScreenshotNeo

BlogHow-to

How to Generate Article Story Images Automatically

Build a repeatable workflow to generate, review, and publish article images, with runnable OpenAI API examples and a WordPress integration path.

By the ScreenshotNeo team29 September 202611 min read

How to Generate Article Story Images Automatically

To generate article story images automatically, connect your publishing workflow to an image-generation API: detect an article that needs an image, build a prompt from its topic and placement, generate an asset, review it, then save and attach the approved file in your CMS. Keep generation and publication as separate steps so an incorrect or misleading image does not go live without review.

This guide covers prompt design, OpenAI Image API and Responses API patterns, a runnable Python example, WordPress integration considerations, quality and output settings, failure handling, and publishing checks. The API and CMS interfaces can change, so check the linked official documentation before deploying.

1. Design the workflow before writing code

Start by deciding what event should request an image and where the result should go. For example, a draft can move to an “image needed” state, which starts generation and stores the result as a pending asset. An editor then approves it and assigns the featured-image or in-article placement.

A reliable workflow separates image generation, editorial review, and CMS publication.
A reliable workflow separates image generation, editorial review, and CMS publication.
  1. Trigger: identify an article that lacks an image, or an editor action that explicitly requests one.
  2. Prepare inputs: collect the title, a short factual summary, intended placement, audience, desired aspect ratio, brand style, and required or prohibited visual elements.
  3. Construct a prompt: state the deliverable and canvas, then describe the subject, visual hierarchy, and treatment. Include exact text or data if the image must contain any.
  4. Generate: send the prompt to a generation endpoint, or use an editing workflow when a reference image needs changes.
  5. Review: check relevance, factual implications, brand fit, accessibility, and rights or policy requirements.
  6. Publish: save the approved file in the CMS, assign its intended placement, and write useful alt text.

Make the request idempotent where possible: associate it with an article ID and image role, and record the prompt and generation status. A retry should not silently create duplicate media attachments. Treat timeouts as an unknown outcome until you check whether the original request completed.

2. Write prompts for a publication slot

A title alone is usually too little direction. Describe what the asset is for and the shape of the canvas. Then specify the main subject, what should draw the eye first, supporting elements, and a coherent visual language. This follows the structure in the official image prompting guide.

Deliverable: featured image for a developer tutorial about automatically generating article illustrations.
Canvas: wide 16:9 editorial illustration, intended for a blog card and article header.
Subject: an article draft moving through a generation and editorial review workflow.
Hierarchy: make the draft and the resulting illustration prominent; show a human review step clearly.
Style: clean geometric shapes, restrained warm colors, consistent with a technical publication.
Constraints: no words, letters, logos, fabricated product screens, or misleading technical diagrams.

Use different prompts for different placements. A featured image often needs a broad composition that survives cropping; an in-article explainer should make one specific idea legible at a smaller size. If an image contains a diagram or exact labels, provide the exact content and verify every detail afterward. Do not rely on a generated image to supply technical facts correctly.

Store the prompt template separately from article text. Pass only the necessary article summary and placement details, and avoid sending private draft material unless your data-handling rules allow it. Keep a record of the prompt version so editorial changes can be traced.

3. Generate an image through the OpenAI API

The Image API is suited to a focused image generation or edit request. OpenAI also documents image generation in the Responses API, which can fit a multi-step interaction where you generate, inspect, and refine. Available controls include size, quality, format, and compression; choose them for the actual CMS slot and site performance needs. See the image generation guide and create image API reference for current parameters and supported values.

Here is a minimal Python example using the OpenAI SDK. Set the API key in the environment rather than embedding it in application code. Confirm the model and parameter names against current documentation when implementing, since API options can change.

import base64
import os
from pathlib import Path
from openai import OpenAI

client = OpenAI(api_key=os.environ["OPENAI_API_KEY"])

prompt = """Create a wide editorial illustration for a developer blog post about
automatically generating article story images. Show an article draft flowing
through image generation and a human review step into a finished illustration.
Clean geometric shapes, restrained warm colors, clear hierarchy. No words,
letters, logos, or UI copy."""

result = client.images.generate(
    model="gpt-image-1",
    prompt=prompt,
    size="1536x1024",
    quality="medium",
    output_format="webp",
    output_compression=80,
)

image_bytes = base64.b64decode(result.data[0].b64_json)
Path("article-story-image.webp").write_bytes(image_bytes)
print("Saved article-story-image.webp")

Install the SDK in your project environment and pin a version after confirming the documented interface you intend to use. The example writes the response bytes locally; it does not attach the file to a CMS or publish an article. Keep those operations in the later approval stage.

Choosing Image API or Responses API

Pattern Good fit Implementation note
Image API One generation or edit from a prepared prompt Simple request and save pipeline
Responses API Generation inside a multi-step interaction or iterative process Useful when a workflow needs to continue with additional input or refinement

Use an edit path when you have a reference asset and want a change to it. Keep the original and generated versions distinct so an editor can compare them. The official documentation describes these capabilities but does not establish a universal winner for quality, cost, or latency; evaluate the workflow against your content and operational needs.

4. Save generated images in WordPress

For WordPress, generation and Media Library storage are separate concerns. The WordPress developer article on its AI Client describes a plugin pattern that sends an image prompt and can save the resulting image to the Media Library. Use that as an integration path, and consult the current WordPress developer guidance for implementation details and API availability.

A safe plugin flow is:

  1. Offer an explicit editor action or a draft-status hook.
  2. Build the prompt from the article title, summary, placement, and site style.
  3. Call the configured image-generation provider through the approved client or server-side integration.
  4. Save the returned file to the Media Library as an unattached or pending item.
  5. Show a preview and require editorial approval.
  6. After approval, attach it to the post and require appropriate alt text.

Keep credentials server-side. Add capability checks, input validation, a generation status, and a way to discard an asset. If generation is asynchronous, show the editor whether the request is queued, complete, failed, or awaiting review. Do not treat a successful API response as permission to publish.

5. Select size, quality, format, and compression

Match the image output to its destination instead of requesting the largest asset by default. A featured image may need more pixels than a small inline illustration, while an editor preview may not need the final delivery settings. The image API reference documents configurable output dimensions, quality, format, and compression; accepted values can depend on the selected model and should be checked in that reference.

  • Size: choose an aspect ratio and dimensions that suit the CMS slot and its crop behavior. Leave enough composition around the subject if responsive crops are used.
  • Quality: use a level suitable for the visible placement. Review the actual file, since the prompt and output settings both affect usefulness.
  • Format: choose a format supported by your publishing and delivery stack. Verify that generated bytes match the file extension and MIME type you store.
  • Compression: balance file size against visible artifacts, then inspect at realistic display dimensions.

Keep the original generated response until review is complete, then create any CMS-specific derivative as a separate step. Check that thumbnails, responsive variants, and cache invalidation behave as expected on your site.

6. Add review, retries, and operational safeguards

Automating the request does not automate editorial judgment. Review images for an inaccurate implication, a mismatch with the article, unwanted artifacts, brand inconsistency, and accessibility. If the image depicts a real process, ensure it does not suggest that software performed an action the article does not describe. Write alt text for the image’s purpose in context; do not merely repeat the prompt.

For a production workflow, track article ID, placement, prompt template version, provider request identifier if available, output metadata, status, reviewer, and CMS media ID. Avoid logging API secrets or unnecessarily retaining sensitive source content. Establish a bounded retry policy for transient failures, and ensure a retry cannot publish twice or leave duplicate attached images.

  • Set a timeout appropriate to the provider’s documented behavior and handle timeouts as ambiguous completion.
  • Retry transient network or service failures with a limit and increasing delay; surface persistent errors to an editor.
  • Do not repeatedly retry invalid prompts, unsupported settings, authentication failures, or policy refusals without changing the cause.
  • Validate response content and dimensions before saving. A nonempty response alone does not establish that an asset is usable.
  • Keep a manual upload path available so an article is not blocked by image generation.

7. Troubleshooting common problems

Symptom Likely cause Fix
Authentication error Missing, invalid, or unavailable server-side API key Check the deployment secret and the provider account configuration; never put the key in browser JavaScript.
Unsupported parameter or size A setting is not accepted for the selected model or endpoint Use the current API reference to select supported values; reduce the request to documented settings.
Image request times out Network interruption or a slow response; completion may be uncertain Record the request state, check for an existing result before retrying, and use a bounded retry strategy.
File cannot be decoded Response was treated as a URL or wrong encoding, or extension and format disagree Follow the response shape for the endpoint, decode returned image data correctly, and validate MIME type before storage.
Image looks unrelated Prompt is vague, summary is noisy, or placement is underspecified Provide a concise factual summary, name the image role, and specify hierarchy and visual treatment.
Wrong crop in the theme CMS or theme crops the uploaded asset to a different ratio Check the real display slot, adjust composition and output dimensions, and preview the CMS crop before approval.
Duplicate media items Retries or status hooks create a new request each time Use an idempotency key or stored per-article generation state and check for an existing pending asset.
Asset generated but not visible Storage, attachment, permissions, or CDN cache step failed Check the Media Library record, post attachment, file permissions, and relevant cache behavior independently.

8. Performance, reliability, and cost

Generation adds an external request and file storage to the publishing path. For a responsive editor experience, run generation as a background job and display status rather than making the entire post-save action wait for image completion. Keep file size appropriate for the placement and let the site create delivery variants where needed. Measure your own end-to-end time and storage use; the sources reviewed do not establish a general latency or cost winner across providers.

A screenshot capture can remove common overlays before saving the page image.
A screenshot capture can remove common overlays before saving the page image.

Estimate operating cost from the provider’s current pricing and your actual request pattern, including retries, edits, and abandoned drafts. Also account for CMS storage and image delivery. Keep review in the workflow because the API capability to generate an image is not a guarantee of factual accuracy or publication readiness. Confirm applicable provider terms and organizational policies before sending content or publishing outputs.

If your article includes a website capture as an explanatory asset, capture it separately from image generation. ScreenshotNeo is a website screenshot API and MCP server; it returns a PNG, JPEG, WebP, or PDF from one GET request, with options for full-page or element captures, viewport and device settings, and other capture controls. It is a capture tool, not an image generator.

Or skip the browser setup

If your story image needs to show a real webpage, you can take a screenshot with one API call instead of running and maintaining a browser. The ScreenshotNeo documentation covers its API and options.

curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp
import requests
r = requests.get("https://api.screenshotneo.com/v1/shot", params={"access_key": "YOUR_API_KEY", "url": "https://stripe.com"}, timeout=90)
open("shot.webp", "wb").write(r.content)
const q = new URLSearchParams({ access_key: 'YOUR_API_KEY', url: 'https://stripe.com' });
const res = await fetch(`https://api.screenshotneo.com/v1/shot?${q}`);
  • Cookie and consent banners, newsletter popups, and chat widgets are removed before the screenshot; each cleanup step can be turned off.
  • Bot checks and CAPTCHAs, blank pages, timeouts, failed loads, and cache hits are never billed. Response headers report the page verdict and billing status.
  • An MCP server provides take_screenshot, get_page_info, and capture_pdf for Claude, Cursor, and other MCP clients.
  • The free plan includes 1,000 screenshots each month with no card. Paid plans start at $5 for 3,000 shots; every feature is on every plan.

Sign up free for 1,000 screenshots a month, with no card.

9. Publishing checklist

  • The prompt identifies the placement, subject, hierarchy, canvas, and style.
  • Output dimensions, quality, and format match the CMS slot and delivery needs.
  • The generated file has been decoded, validated, and saved without exposing credentials.
  • An editor has reviewed relevance, factual implications, artifacts, and brand fit.
  • Alt text describes the image’s purpose rather than its generation prompt.
  • The approved asset is attached to the correct post and crop preview is acceptable.
  • Retries and duplicate requests are controlled, and a manual fallback is available.

10. FAQ

Can I publish images without a human review?

The generation and CMS integration capabilities do not establish that unattended publishing is safe. Keep review for relevance, factual implications, accessibility, and policy checks unless your own editorial process has explicitly validated a narrower use.

Should every article get a generated image?

No. Generate an asset when it serves the article’s purpose and fits its placement. An irrelevant decorative image adds little and can confuse readers.

Can I use a reference image?

The image API documentation includes editing workflows. Check current endpoint behavior and parameters, and confirm that you have the rights and approvals needed to use the reference.

Does WordPress automatically make generated images accessible?

Saving a file to the Media Library does not decide its meaning in context. An editor should provide suitable alt text and verify how the image is presented.

Which provider is cheapest or fastest?

The official sources covered here do not establish a comparable provider ranking for price, latency, or image quality. Check current pricing and benchmark your own prompts, output settings, and review workflow.