Guides · Tooling & Windows gotchas · Published 2026-09-13 · 3 min read

Generating Site Images With an AI Model From Node — A Small Job Runner, Prompt Files, Cost Logging Per Image, and Post-Processing With sharp

How we generate hero images, category art and book covers with an image model from a Node script: named jobs in a file, one prompt each, a cost log that adds up in local currency, a review step before anything is published, and sharp to crop and compress the output.

Image models are cheap per picture and expensive per habit. A script that generates on demand, logs what each image cost, and forces a look at the result before it ships keeps them useful. This is the shape of the small tool we use for hero images and covers across several sites.

Jobs in a file, not in a chat

Every image we might want is a named job in one script: an output path, a prompt, a target size and aspect, and a note about where it is used. Generating is node gen_images.js <job-name>. This makes prompts reviewable in version control, lets you regenerate a single asset after a design change, and stops the drift of prompts living in a conversation somewhere.

const JOBS = {
  'cf-hero': { out: 'cashfate-com/public/img/hero.jpg', size: [1600, 900],
    prompt: 'Calm editorial photograph, morning light on a wooden desk with a passport, a bank card and a small notebook, muted teal tones, no text' },
};

Prompt habits that save re-runs

Cost logging

The API returns token or image counts; multiply by the published price, convert to your currency at a fixed rate you set in the script, and append a line to a log file per run: job, cost, timestamp. Print the running total. The point is not accounting precision; it is that the person running the script sees "this batch cost about the price of a coffee" and decides whether a second pass is worth it. A budget guard that refuses to run more than a set number of images without an explicit flag prevents an accidental loop from generating hundreds.

Review before publish

Write the raw output next to the final path with a suffix, open it, and only then run the post-processing step that writes the final file. Failures are visual: a hand with six fingers, a sign with gibberish, a horizon that is not level. No check catches these except looking.

Post-processing with sharp

The model's output is rarely the exact size or format you serve. A single sharp pipeline handles the rest: crop to the target aspect with attention-based positioning, resize to the served dimensions, and write a JPEG at a quality around 80, plus a WebP if the templates use <picture>. For thumbnails, resize again from the master rather than from the compressed output. The mechanics are in resizing, cropping and composing images with sharp.

Where AI images fit, and where they do not

They work for atmosphere: heroes, section headers, abstract category art, book backgrounds. They do not work for anything a reader will treat as evidence, such as a photograph of a specific place, a product, or a person. For a travel site that means generated images stay decorative and real photographs, or none, illustrate the actual station or pier. Say so in the site's disclosure page.

Common mistakes

Summary

Keep prompts as named jobs in a script, log the cost of every image in a currency you feel, look at each result before it is published, and finish with a sharp pipeline that crops and compresses. Use the images for mood, not for facts.

Related guides