Skip to content

fix(image): preserve resolution when changing aspect ratio#13324

Merged
tjx666 merged 2 commits into
lobehub:canaryfrom
BillionClaw:fix/image-resolution-aspect-ratio
Apr 28, 2026
Merged

fix(image): preserve resolution when changing aspect ratio#13324
tjx666 merged 2 commits into
lobehub:canaryfrom
BillionClaw:fix/image-resolution-aspect-ratio

Conversation

@BillionClaw

Copy link
Copy Markdown
Contributor

When using models that support resolution enum (1K/2K/4K), selecting a different aspect ratio would cause the resolution to be lost. The setAspectRatio action now preserves the resolution parameter if it exists in the current parameters. Fixes #13283

@vercel

vercel Bot commented Mar 26, 2026

Copy link
Copy Markdown

@BillionClaw is attempting to deploy a commit to the LobeHub OSS Team on Vercel.

A member of the Team first needs to authorize it.

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We've reviewed this pull request using the Sourcery rules engine

@lobehubbot

Copy link
Copy Markdown
Member

@tjx666 - This is an image generation fix (preserve resolution when changing aspect ratio). Please take a look.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 6ea05a4c0f

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment on lines +239 to +243
// Preserve resolution if it exists in current parameters (models like nanoBanana2 use resolution enum)
// This ensures 4K/2K resolution is maintained when changing aspect ratios
if ('resolution' in parameters && parameters.resolution !== undefined) {
newParams.resolution = parameters.resolution;
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Add regression coverage for resolution preservation

This change updates setAspectRatio to keep parameters.resolution, but the commit does not add a matching test case in src/store/image/slices/generationConfig/action.test.ts; .agents/skills/code-review/SKILL.md explicitly requires bug fixes to include tests for the fixed scenario. Without a regression test for models that expose both aspectRatio and resolution (for example Nano Banana / Grok image models), this behavior can regress again without any CI failure.

Useful? React with 👍 / 👎.

@arvinxx

arvinxx commented Mar 27, 2026

Copy link
Copy Markdown
Member

@BillionClaw plz check codex review

@codecov

codecov Bot commented Mar 27, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 66.66667% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 66.76%. Comparing base (926de07) to head (6ea05a4).
⚠️ Report is 6 commits behind head on canary.

Additional details and impacted files
@@           Coverage Diff            @@
##           canary   #13324    +/-   ##
========================================
  Coverage   66.76%   66.76%            
========================================
  Files        1889     1888     -1     
  Lines      151446   151439     -7     
  Branches    14506    15220   +714     
========================================
+ Hits       101112   101115     +3     
+ Misses      50222    50212    -10     
  Partials      112      112            
Flag Coverage Δ
app 58.21% <66.66%> (+<0.01%) ⬆️
database 96.64% <ø> (ø)
packages/agent-runtime 89.61% <ø> (ø)
packages/context-engine 83.22% <ø> (ø)
packages/conversation-flow 92.36% <ø> (ø)
packages/file-loaders 87.02% <ø> (ø)
packages/memory-user-memory 66.68% <ø> (ø)
packages/model-bank 99.85% <ø> (ø)
packages/model-runtime 84.48% <ø> (ø)
packages/prompts 67.76% <ø> (ø)
packages/python-interpreter 92.90% <ø> (ø)
packages/ssrf-safe-fetch 0.00% <ø> (ø)
packages/utils 90.41% <ø> (ø)
packages/web-crawler 88.82% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Components Coverage Δ
Store 66.07% <66.66%> (+<0.01%) ⬆️
Services 49.56% <ø> (ø)
Server 67.38% <ø> (+0.01%) ⬆️
Libs 51.06% <ø> (ø)
Utils 91.01% <ø> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

When using models like nanoBanana2 that support resolution (1K/2K/4K),
selecting a different aspect ratio would cause the resolution to be lost.

This ensures the resolution parameter is preserved when calling setAspectRatio,
fixing the issue where 4K resolution would be reset to 1K when changing
aspect ratios.
@tjx666 tjx666 force-pushed the fix/image-resolution-aspect-ratio branch from 6ea05a4 to 554d3f1 Compare April 2, 2026 16:43
@yincangshiwei

Copy link
Copy Markdown

When can it be processed? Version 2.1.48 is still not functioning properly. @tjx666 @BillionClaw

@tjx666

tjx666 commented Apr 13, 2026

Copy link
Copy Markdown
Member

Hi @BillionClaw, two things to address before merge:

  1. Please add a regression test. src/store/image/slices/generationConfig/action.test.ts already has an Aspect Ratio Setting describe block — add a case there that seeds parameters.resolution (e.g. '4K') with a schema exposing a resolution enum, calls setAspectRatio('16:9'), and asserts the resolution is preserved. Otherwise this bug can silently regress.

  2. Validate the preserved value against the schema's enum. The current patch unconditionally copies parameters.resolution into newParams. If the (current or later-applied) parametersSchema.resolution.enum doesn't contain the previous value, we end up carrying an invalid value forward. Please check membership in parametersSchema.resolution.enum before copying, and fall back to the schema default (or drop the field) when it's not a valid option.

@Mati0kez

Copy link
Copy Markdown

Addressed Review Feedback

Thanks for the review @tjx666. I've addressed both comments:

1. Added Regression Test ✅

Added 3 new test cases in src/store/image/slices/generationConfig/action.test.ts under the Aspect Ratio Setting describe block:

  • should preserve resolution when changing aspect ratio for models with resolution enum — verifies 4K resolution is preserved when schema has resolution enum
  • should strip resolution when new schema does not support the current resolution value — verifies resolution is stripped if not in new schema's enum
  • should strip resolution when schema has no resolution enum — verifies resolution is stripped when schema has no resolution support

2. Added Enum Validation ✅

Updated setAspectRatio in action.ts to validate the preserved resolution against the schema's enum:

// Preserve resolution if it exists in current parameters (models like nanoBanana2 use resolution enum)
// Only preserve if the new schema's resolution enum contains the current value
if (
  'resolution' in parameters &&
  parameters.resolution !== undefined &&
  parametersSchema?.resolution?.enum &&
  parametersSchema.resolution.enum.includes(parameters.resolution)
) {
  newParams.resolution = parameters.resolution;
} else if (
  'resolution' in parameters &&
  parameters.resolution !== undefined &&
  ( !parametersSchema?.resolution?.enum ||
    !parametersSchema.resolution.enum.includes(parameters.resolution))
) {
  // Resolution value is not valid for new schema - strip it
  delete newParams.resolution;
}

The implementation now:

  • ✅ Preserves resolution when the new schema supports the same resolution enum value
  • ✅ Strips resolution when the new schema's enum doesn't include the current value
  • ✅ Strips resolution when the new schema has no resolution enum at all

I've pushed the changes to my fork at Mati0kez/lobehub:canary and created a new PR to supersede this one since I don't have write access to the original branch.

@bobo-xxx

Copy link
Copy Markdown

Test comment from API

@sjodu

sjodu commented Apr 23, 2026

Copy link
Copy Markdown

The fix has been implemented with regression tests. It's currently waiting for Vercel deployment authorization from a LobeHub OSS Team member.

@onthebed

Copy link
Copy Markdown

I'll get the CLA signed — will follow up once it's done.

@dosubot dosubot Bot added the size:XS This PR changes 0-9 lines, ignoring generated files. label Apr 28, 2026
@tjx666 tjx666 merged commit dacc779 into lobehub:canary Apr 28, 2026
2 of 4 checks passed
@lobehubbot

Copy link
Copy Markdown
Member

❤️ Great PR @BillionClaw ❤️

The growth of project is inseparable from user feedback and contribution, thanks for your contribution! If you are interesting with the lobehub developer community, please join our discord and then dm @arvinxx or @canisminor1990. They will invite you to our private developer channel. We are talking about the lobe-chat development or sharing ai newsletter around the world.

sxueck pushed a commit to sxueck/lobehub that referenced this pull request Apr 28, 2026
…3324)

Co-authored-by: BillionClaw <267901332+BillionClaw@users.noreply.github.com>
Co-authored-by: YuTengjing <ytj2713151713@gmail.com>
mutoe pushed a commit to mutoe/lobehub that referenced this pull request May 1, 2026
…3324)

Co-authored-by: BillionClaw <267901332+BillionClaw@users.noreply.github.com>
Co-authored-by: YuTengjing <ytj2713151713@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:XS This PR changes 0-9 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Incorrect Resolution Size in Image Generation

9 participants