All articles

Local image generation with FLUX.1 schnell and stable-diffusion.cpp

The Apache-2.0 FLUX.1 schnell model, stable-diffusion.cpp with GGUF quantization, four-step sampling, seeds and generation records, img2img and chroma-key background removal.

t.Turgay
Local image generation with FLUX.1 schnell and stable-diffusion.cpp

Concept art and placeholder sprites for a game prototype can be generated with a local image model. FLUX.1 [schnell] is an open-weight model that produces results in few steps; stable-diffusion.cpp runs it on consumer graphics cards with quantized GGUF files and no Python environment. This article covers the model, the command-line parameters, reproducible generation records and turning a generated image into a game asset.

Model, license and components

FLUX.1 [schnell] is a 12-billion-parameter rectified flow transformer from Black Forest Labs. Trained with latent adversarial diffusion distillation, it generates images in 1 to 4 steps. It is licensed under Apache-2.0, which grants broad permission including commercial use. The dev model of the same family ships under a separate non-commercial license, so read the license of each model separately.

Running it takes four parts: the diffusion model, the VAE (ae) that turns the latent result into pixels, and two text encoders, CLIP-L and T5-XXL. In Python, the diffusers FluxPipeline uses guidance_scale=0 and 4 steps for schnell. The examples below use the C++ based stable-diffusion.cpp instead.

Hugging Face — FLUX.1 [schnell] model card

stable-diffusion.cpp and GGUF quantization

stable-diffusion.cpp is a C++ implementation built on ggml and compiles into a single executable for back ends such as CUDA, Vulkan or the CPU. Model weights can be quantized in GGUF format: q8_0 stays close in quality, and q4_0 roughly halves memory use. According to the table on the project's FLUX page, flux-dev uses about 12 GB with q8_0 and about 6.4 GB with q4_0.

T5-XXL is a large encoder; --clip-on-cpu runs the text encoders on the processor to relieve graphics memory, at the cost of a slower encoding step. Schnell does not use classifier-free guidance (CFG), so pass --cfg-scale 1.0, the euler sampler and 4 steps. Check the exit code when the command fails; a half-written PNG must not move on to later steps.

# Paths are illustrative; sd-cli is the stable-diffusion.cpp command-line tool.
$models = 'D:\models\flux'
$sdArgs = @(
  '--diffusion-model', "$models\flux1-schnell-q8_0.gguf",
  '--vae',             "$models\ae.safetensors",
  '--clip_l',          "$models\clip_l.safetensors",
  '--t5xxl',           "$models\t5xxl_fp16.safetensors",
  '--clip-on-cpu',
  '--cfg-scale', '1.0', '--sampling-method', 'euler', '--steps', '4',
  '-W', '768', '-H', '768', '--seed', '22',
  '-p', 'pixel art space rover, side view, plain flat bright green background',
  '-o', 'out\rover-22.png'
)
& .\sd-cli.exe @sdArgs
if ($LASTEXITCODE -ne 0) { throw "sd-cli failed with exit code $LASTEXITCODE" }

stable-diffusion.cpp — FLUX

Seeds, batches and a generation record

The same model files, prompt, seed, step count, size and sampler usually give the same image with the same tool version; small differences can appear when the driver or back end changes. When choosing a candidate, generate a batch with several seeds and record the seed you keep. Putting the seed in the file name makes it easy to find later which attempt was chosen.

Keep a record file for every asset: the file's SHA-256 hash, the model file names and license, the prompt, seed, steps, size, the img2img source and the post-processing applied. That record is the single reference for license audits, AI content disclosures on stores and regenerating the image.

{
  "asset": "rover-side",
  "file": "sprites/rover-side.png",
  "sha256": "<sha-256 of the final file>",
  "generator": "stable-diffusion.cpp (sd-cli)",
  "models": {
    "diffusion": "flux1-schnell-q8_0.gguf",
    "vae": "ae.safetensors",
    "textEncoders": ["clip_l.safetensors", "t5xxl_fp16.safetensors"]
  },
  "license": "Apache-2.0 (FLUX.1 [schnell])",
  "prompt": "pixel art space rover, side view, plain flat bright green background",
  "seed": 22, "steps": 4, "cfgScale": 1.0, "size": [768, 768],
  "init": { "image": "sketches/rover.png", "strength": 0.55 },
  "postprocess": ["chroma-key hue 65-170", "crop", "nearest-neighbour 96x96"]
}

Prompting: colour names and negative prompts

FLUX can render text from the prompt into the image. Writing a colour code such as #00FF00 in the prompt sometimes makes that code appear as letters in the picture; describing colours by name, as in "flat bright green background", gives more reliable results. Write the viewpoint, art style, subject and background as short, separate phrases.

With CFG off (scale 1.0), a negative prompt takes no part in the computation. Exclude unwanted elements with a positive phrase: write "plain flat background" instead of "no clutter". Keeping a shared prompt body for an asset family and changing only the subject improves style consistency across sprites.

img2img: generating from a sketch

A rough sketch or an earlier generation is passed as the initial image with -i, and --strength sets how much the image may change. Low values keep the shape; high values give the model more freedom. For sprites whose silhouette and proportions must stay fixed, try values in the middle.

Pre-tinting the initial image with the target palette makes the model take colours from the sketch more than from the prompt. Trying different seeds with the same sketch produces a set of variations that keep the same silhouette. Generating at the sketch's size and aspect ratio avoids losses in the later cropping step.

Removing the background with a chroma key

When the model draws the subject on a flat green background, the background is selected in HSV space with a hue range and a saturation threshold. Selection based on RGB distance is inconsistent in shadows and highlights, while hue is largely independent of brightness. Pixel art does not want semi-transparent edges, so alpha stays binary: a pixel is either fully visible or fully transparent.

If the subject itself contains green tones, choose a distant background colour such as magenta. After keying, crop the image to the bounding box of visible pixels, scale it to the target size with nearest-neighbour sampling and build sprite sheets with integer zoom; interpolation blurs pixel edges.

// rgba: width * height * 4 bytes, e.g. raw output from an image library
function hsv(r, g, b) {
  const max = Math.max(r, g, b), min = Math.min(r, g, b), d = max - min;
  let h = 0;
  if (d !== 0) {
    if (max === r) h = ((g - b) / d) % 6;
    else if (max === g) h = (b - r) / d + 2;
    else h = (r - g) / d + 4;
    h *= 60;
    if (h < 0) h += 360;
  }
  return { h, s: max === 0 ? 0 : d / max, v: max / 255 };
}

function removeGreen(rgba, minHue = 65, maxHue = 170, minSat = 0.35, minVal = 0.2) {
  for (let i = 0; i < rgba.length; i += 4) {
    const { h, s, v } = hsv(rgba[i], rgba[i + 1], rgba[i + 2]);
    const background = h >= minHue && h <= maxHue && s >= minSat && v >= minVal;
    rgba[i + 3] = background ? 0 : 255;      // binary alpha: no half-transparent fringe
  }
  return rgba;
}

Related technical articles

You have reached the end of this orbit.
Explore more articles
turgay.A little code, a few pixels, a lot of curiosity.© 2026 · Made on Earth