feat: ensure image output format matches file extension
All checks were successful
Continuous Integration / Build Package (push) Successful in 30s
Continuous Integration / Lint, Check & Test (push) Successful in 45s

- Add hokusai/image.py with Pillow-based format detection and conversion
- Pass output_format to OpenAI gpt-image models and BFL API
- Convert mismatched images after provider writes (fallback for all providers)
- Handle RGBA-to-RGB flattening for JPEG targets
- Add Pillow dependency
This commit is contained in:
Konstantin Fickel 2026-02-21 19:04:33 +01:00
parent d8e0ed561d
commit 770f408dad
Signed by: kfickel
GPG key ID: A793722F9933C1A5
7 changed files with 348 additions and 92 deletions

View file

@ -19,6 +19,7 @@ from hokusai.config import (
ProjectConfig,
)
from hokusai.graph import build_graph, get_build_order, get_subgraph_for_target
from hokusai.image import ensure_image_format
from hokusai.prompt import extract_placeholder_files, resolve_prompt
from hokusai.providers import Provider
from hokusai.providers.blackforest import BlackForestProvider
@ -170,6 +171,7 @@ async def _build_single_target(
if isinstance(target_cfg, DownloadTargetConfig):
await _download_target(target_name, target_cfg, project_dir)
ensure_image_format(output_path)
return
model_info = resolve_model(target_name, target_cfg, config.defaults)
@ -184,6 +186,9 @@ async def _build_single_target(
project_dir=project_dir,
)
# Ensure the output image format matches the file extension.
ensure_image_format(output_path)
def _cleanup_stale_targets(
config: ProjectConfig,