Skip to content

feat: expose img2img CLI flags for Flux.2 Klein#358

Merged
filipstrand merged 1 commit intofilipstrand:mainfrom
terribilissimo:feature/flux2-klein-img2img
Feb 17, 2026
Merged

feat: expose img2img CLI flags for Flux.2 Klein#358
filipstrand merged 1 commit intofilipstrand:mainfrom
terribilissimo:feature/flux2-klein-img2img

Conversation

@terribilissimo
Copy link
Contributor

@terribilissimo terribilissimo commented Feb 16, 2026

Add --image-path and --image-strength to mflux-generate-flux2, following the same pattern used by flux_generate.py (Flux.1).

Note: This is independent of #353 (Z-Image enhancements), and can be reviewed/merged separately.

Three additions:

  1. parser.add_image_to_image_arguments(required=False)
  2. reference_image_path=args.image_path in DimensionResolver.resolve()
  3. image_path + image_strength passed to model.generate_image()

Summary

The Flux2Klein Python class already implements full img2img support via
_prepare_img2img_latents(), accepting image_path and image_strength
parameters in generate_image(). However, the mflux-generate-flux2 CLI
does not register --image-path / --image-strength, so users cannot
access img2img from the command line.

This PR adds 3 lines to flux2_generate.py to expose these flags,
following the exact same pattern used by flux_generate.py (Flux.1):

  1. parser.add_image_to_image_arguments(required=False)
  2. reference_image_path=args.image_path in DimensionResolver.resolve()
  3. image_path=args.image_path + image_strength=args.image_strength in generate_image()

When --image-path is not provided, behavior is identical to upstream.

Why this is different from mflux-generate-flux2-edit

Flux.2 Klein already has an image-conditioned editing CLI
(mflux-generate-flux2-edit with --image-paths), but that is a
fundamentally different operation from img2img:

img2img (--image-path) Image-conditioned editing (--image-paths)
Purpose Transform a single input image while preserving its overall structure and composition Use one or more reference images as semantic context for generation
How it works Encodes the input into latent space, adds noise controlled by --image-strength, then denoises — the result follows the spatial layout of the original Reference images are injected as conditioning tokens alongside the text prompt — the model draws on their content freely
Strength control --image-strength (0.0 = ignore input, 1.0 = pure noise) controls how much of the original is preserved No strength parameter — the prompt determines what changes
Number of inputs Exactly 1 image 1 or more reference images
Typical use cases Style transfer, color grading, detail refinement, artistic re-interpretation of a photo "Put these sunglasses on this person", combining elements from multiple images, subject-driven editing
CLI command mflux-generate-flux2 (this PR) mflux-generate-flux2-edit (already exists)

Every other generation command in MFLUX that supports img2img
(Flux.1, FIBO, Qwen Image, Z-Image) already exposes --image-path /
--image-strength in its CLI. Flux.2 Klein is the only model where the
underlying class supports it but the CLI does not — this PR closes that gap.

Testing

Tested on Apple Silicon with flux2-klein-4b (distilled) and
flux2-klein-base-9b (undistilled). Verified:

  • txt2img (no new flags) produces identical output to upstream
  • img2img with --image-path + --image-strength works correctly
  • DimensionResolver auto-sizes from the reference image when --width/--height are omitted

Checklist

  • Single file changed (flux2_generate.py)
  • No new dependencies
  • Backward-compatible (no flags = identical behavior)
  • Follows existing pattern from flux_generate.py

Add --image-path and --image-strength to mflux-generate-flux2,
following the same pattern used by flux_generate.py (Flux.1).

Three additions:
1. parser.add_image_to_image_arguments(required=False)
2. reference_image_path=args.image_path in DimensionResolver.resolve()
3. image_path + image_strength passed to model.generate_image()
@filipstrand
Copy link
Owner

Should have been there from the start :). Will make a 0.16.5 release with this included.

@filipstrand filipstrand merged commit 47a3c64 into filipstrand:main Feb 17, 2026
1 check passed
@terribilissimo
Copy link
Contributor Author

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants