[GH-ISSUE #3726] Feature Request: Dynamic NovelAI image resolution based on character count #2010

Closed
opened 2026-10-21 05:44:34 +07:00 by bsakaguchi · 1 comment
Owner

Originally created by @jswen4-tech on GitHub (Jul 16, 2026).
Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/3726

Originally assigned to: @SpicyMarinara on GitHub.

Feature Request: Dynamic NovelAI image resolution based on character count

Summary

Automatically choose the NovelAI image resolution (portrait / square / landscape) based on how many characters the illustrator prompt depicts, instead of always using one fixed size from settings.

Problem

Marinara currently sends a single fixed resolution (from the user's image settings) for every NovelAI generation. But the ideal aspect ratio depends heavily on how many characters are in the scene:

  • 1 character — a portrait orientation frames a single figure well; landscape wastes most of the frame on background and makes the figure (and their face) small.
  • 2 characters — a square fits a pair naturally.
  • 3+ characters — landscape is needed to hold everyone in frame without cramming.

With one fixed size, you're always wrong for two of the three cases. A solo portrait beat generated at landscape puts the character small in a wide empty frame; a three-character scene at portrait crams everyone together and encourages the model to merge or drop figures.

This matters most for face quality: at a fixed landscape size, a solo character occupies a small fraction of the frame, so the face gets very few pixels and renders poorly. Choosing portrait for solo shots meaningfully increases face pixel count with no extra cost.

Proposed behavior

Derive the subject count from the illustrator prompt and pick a matching size:

Characters Size Orientation
1 832x1216 portrait
2 1024x1024 square
3+ 1216x832 landscape

All three are within NovelAI's Opus-free pixel budget (<= 1024x1024 equivalent), so this costs no additional Anlas.

Detection: the count can be read directly from the prompt that the illustrator agent already produces:

  1. Primary signal — the subject-count tokens in the base fragment (1girl, 2girls, 1boy, 3boys, 1other). These follow the standard NovelAI/booru convention and are summed across matches.
  2. Fallback signal — the pipe structure. Marinara's illustrator template emits base | char1 | char2 | ..., so segments - 1 is the character count.
  3. No signal — return null and fall back to the user's configured size, so free-form prompts are unaffected.

Working implementation

I have this running locally against packages/server/src/services/image/image-generation.ts and it's been stable in daily use. The change is contained:

  • A size table constant.
  • A detectNovelAiSubjectCount(prompt) helper (regex over the base fragment, with the pipe-count fallback).
  • A novelAiSizeForSubjectCount(count) mapper.
  • resolveNovelAiSize(request, prompt) gains the prompt parameter and prefers the dynamic size when a count is detectable, falling back to request.width/height otherwise.

Existing pixel-clamping logic is unchanged and still applies afterward. I'm happy to open a PR if there's interest.

Open questions / design notes

  • Opt-out: my local version gates this behind an env var (NOVELAI_DYNAMIC_SIZE=off) so it can be disabled. A proper UI toggle would probably be better.
  • Configurable tiers: the three sizes are currently hardcoded. They could be exposed as settings, though sensible defaults may be enough for most users.
  • Non-template prompts: users who don't use the built-in illustrator template may not emit count tokens or pipes. The null-fallback keeps their behavior identical to today, so this is backward compatible.
  • Scope: this is NovelAI-specific as written, since the size tiers are chosen around NovelAI's free pixel budget. Other providers would need their own tables if this were generalized.
  • Interaction with request dimensions: note that Marinara always populates request.width/height from user settings, so treating those as an "explicit override" would permanently disable dynamic sizing. My implementation lets the prompt-derived size win when a count is detected, with request dims as the fallback. That precedence is worth a design decision.
Originally created by @jswen4-tech on GitHub (Jul 16, 2026). Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/3726 Originally assigned to: @SpicyMarinara on GitHub. # Feature Request: Dynamic NovelAI image resolution based on character count ## Summary Automatically choose the NovelAI image resolution (portrait / square / landscape) based on how many characters the illustrator prompt depicts, instead of always using one fixed size from settings. ## Problem Marinara currently sends a single fixed resolution (from the user's image settings) for every NovelAI generation. But the ideal aspect ratio depends heavily on how many characters are in the scene: - **1 character** — a portrait orientation frames a single figure well; landscape wastes most of the frame on background and makes the figure (and their face) small. - **2 characters** — a square fits a pair naturally. - **3+ characters** — landscape is needed to hold everyone in frame without cramming. With one fixed size, you're always wrong for two of the three cases. A solo portrait beat generated at landscape puts the character small in a wide empty frame; a three-character scene at portrait crams everyone together and encourages the model to merge or drop figures. This matters most for **face quality**: at a fixed landscape size, a solo character occupies a small fraction of the frame, so the face gets very few pixels and renders poorly. Choosing portrait for solo shots meaningfully increases face pixel count with no extra cost. ## Proposed behavior Derive the subject count from the illustrator prompt and pick a matching size: | Characters | Size | Orientation | |---|---|---| | 1 | 832x1216 | portrait | | 2 | 1024x1024 | square | | 3+ | 1216x832 | landscape | All three are within NovelAI's Opus-free pixel budget (<= 1024x1024 equivalent), so this costs no additional Anlas. **Detection:** the count can be read directly from the prompt that the illustrator agent already produces: 1. **Primary signal** — the subject-count tokens in the base fragment (`1girl`, `2girls, 1boy`, `3boys`, `1other`). These follow the standard NovelAI/booru convention and are summed across matches. 2. **Fallback signal** — the pipe structure. Marinara's illustrator template emits `base | char1 | char2 | ...`, so `segments - 1` is the character count. 3. **No signal** — return null and fall back to the user's configured size, so free-form prompts are unaffected. ## Working implementation I have this running locally against `packages/server/src/services/image/image-generation.ts` and it's been stable in daily use. The change is contained: - A size table constant. - A `detectNovelAiSubjectCount(prompt)` helper (regex over the base fragment, with the pipe-count fallback). - A `novelAiSizeForSubjectCount(count)` mapper. - `resolveNovelAiSize(request, prompt)` gains the prompt parameter and prefers the dynamic size when a count is detectable, falling back to `request.width/height` otherwise. Existing pixel-clamping logic is unchanged and still applies afterward. I'm happy to open a PR if there's interest. ## Open questions / design notes - **Opt-out:** my local version gates this behind an env var (`NOVELAI_DYNAMIC_SIZE=off`) so it can be disabled. A proper UI toggle would probably be better. - **Configurable tiers:** the three sizes are currently hardcoded. They could be exposed as settings, though sensible defaults may be enough for most users. - **Non-template prompts:** users who don't use the built-in illustrator template may not emit count tokens or pipes. The null-fallback keeps their behavior identical to today, so this is backward compatible. - **Scope:** this is NovelAI-specific as written, since the size tiers are chosen around NovelAI's free pixel budget. Other providers would need their own tables if this were generalized. - **Interaction with request dimensions:** note that Marinara always populates `request.width/height` from user settings, so treating those as an "explicit override" would permanently disable dynamic sizing. My implementation lets the prompt-derived size win when a count is detected, with request dims as the fallback. That precedence is worth a design decision.
bsakaguchi 2026-10-21 05:44:34 +07:00
Author
Owner

@SpicyMarinara commented on GitHub (Jul 17, 2026):

Resolved by #3732, now merged into staging.

<!-- gh-comment-id:5000939545 --> @SpicyMarinara commented on GitHub (Jul 17, 2026): Resolved by #3732, now merged into staging.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Pasta-Devs/Marinara-Engine#2010
No description provided.