Skip to content

feat: add unflatten handler - #248

Merged
pi0 merged 5 commits into
unjs:mainfrom
nathanchase:feat/add-unflatten-handler
Jul 26, 2026
Merged

feat: add unflatten handler#248
pi0 merged 5 commits into
unjs:mainfrom
nathanchase:feat/add-unflatten-handler

Conversation

@nathanchase

@nathanchase nathanchase commented Nov 22, 2024

Copy link
Copy Markdown
Contributor

This pull request introduces a new handler function to the src/handlers/handlers.ts file. The new function, unflatten, is experimental and its API may change in the future.

New handler function added:

  • src/handlers/handlers.ts: Added the unflatten handler, which calls the unflatten method on the provided pipe. This feature is marked as experimental.

See https://sharp.pixelplumbing.com/api-operation#unflatten for more information.

Summary by CodeRabbit

  • New Features

    • Added an unflatten image-processing operation, including support as a modifier option, to help restore image data that was previously flattened.
  • Documentation

    • Updated the “Modifiers” table formatting in the README (whitespace/alignment tweaks) so the table renders cleanly and remains properly aligned.

@pi0

pi0 commented Nov 22, 2024

Copy link
Copy Markdown
Member

Thanks for PR dear @nathanchase. Wondering is it worth to wait for sharp feature to be stable first?

Do you have some more context why it is in experimental state?

@codecov

codecov Bot commented Nov 22, 2024

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 33.33333% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 74.69%. Comparing base (70acd53) to head (1ba36ef).

Files with missing lines Patch % Lines
src/handlers/handlers.ts 33.33% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #248      +/-   ##
==========================================
- Coverage   75.00%   74.69%   -0.31%     
==========================================
  Files           8        8              
  Lines         412      415       +3     
  Branches      109      109              
==========================================
+ Hits          309      310       +1     
- Misses         85       87       +2     
  Partials       18       18              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 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.

@nathanchase

Copy link
Copy Markdown
Contributor Author

Thanks for PR dear @nathanchase. Wondering is it worth to wait for sharp feature to be stable first?

Do you have some more context why it is in experimental state?

I don't have any knowledge of why it's experimental. I just know that I have an immediate use case for it with https://github.com/nuxt/image to make all images with a solid white background become transparent backgrounds. I happened to notice it wasn't wired up to sharp's implementation, so this was just meant as a means of connecting to the unflatten functionality that already exists so that I could use it.

@nathanchase

Copy link
Copy Markdown
Contributor Author

For what it's worth, unflatten has been in sharp since April 2023.
lovell/sharp#1648 (comment)

@pi0
pi0 self-requested a review as a code owner July 23, 2025 11:38
@pi0 pi0 changed the title feat: add experimental unflatten handler for image processing feat: add unflatten handler Jul 26, 2026
Comment thread src/handlers/handlers.ts Outdated
@coderabbitai

coderabbitai Bot commented Jul 26, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 917e96fb-1c5a-4409-b0ac-c084b2e96cf0

📥 Commits

Reviewing files that changed from the base of the PR and between a371c17 and 1ba36ef.

📒 Files selected for processing (1)
  • src/ipx.ts

📝 Walkthrough

Walkthrough

Adds unflatten to the public modifier interface and exports a handler that invokes pipe.unflatten(). The README Modifiers table formatting is adjusted around the blur and unflatten rows.

Changes

Unflatten modifier

Layer / File(s) Summary
Export and document unflatten
src/ipx.ts, src/handlers/handlers.ts, README.md
The modifier interface accepts unflatten, the handler calls pipe.unflatten() without arguments, and the Modifiers table formatting is updated around the new entry.

Estimated code review effort: 1 (Trivial) | ~3 minutes

Suggested reviewers: pi0

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: adding an unflatten handler.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@pi0 pi0 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Seems not experimental anymore! Thanks!

@coderabbitai coderabbitai 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.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@README.md`:
- Around line 168-169: Update the blur and unflatten rows in the operation
table: add blur’s missing fourth cell and trailing table delimiter, and mark
unflatten as experimental while preserving its existing documentation link and
example path.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 2a2b3351-5d2e-4ca4-a8df-cab5488f822d

📥 Commits

Reviewing files that changed from the base of the PR and between aa94ce2 and e3fb037.

📒 Files selected for processing (2)
  • README.md
  • src/handlers/handlers.ts

Comment thread README.md

@coderabbitai coderabbitai 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.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
README.md (1)

192-193: 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Add the missing comments cells to these table rows.

Lines 192-193 contain only three cells instead of the four declared by the header, so the Markdown table is malformed and may render with shifted columns. Add an empty fourth cell and trailing delimiter to both rows.

Proposed fix
-| width / w      | [Docs](https://sharp.pixelplumbing.com/api-resize#resize)       | `/width_200/buffalo.png` or `/w_200/buffalo.png`     |
-| height / h     | [Docs](https://sharp.pixelplumbing.com/api-resize#resize)       | `/height_200/buffalo.png` or `/h_200/buffalo.png`    |
+| width / w      | [Docs](https://sharp.pixelplumbing.com/api-resize#resize)       | `/width_200/buffalo.png` or `/w_200/buffalo.png`     | |
+| height / h     | [Docs](https://sharp.pixelplumbing.com/api-resize#resize)       | `/height_200/buffalo.png` or `/h_200/buffalo.png`    | |
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@README.md` around lines 192 - 193, Add the missing empty comments cell and
trailing table delimiter to both the width / w and height / h rows in the
Markdown table, preserving their existing parameter, documentation, and example
cells.

Source: Linters/SAST tools

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Outside diff comments:
In `@README.md`:
- Around line 192-193: Add the missing empty comments cell and trailing table
delimiter to both the width / w and height / h rows in the Markdown table,
preserving their existing parameter, documentation, and example cells.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: abe4c1d3-8f95-46c5-99b2-a1213ecf7d4a

📥 Commits

Reviewing files that changed from the base of the PR and between e3fb037 and a371c17.

📒 Files selected for processing (2)
  • README.md
  • src/handlers/handlers.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/handlers/handlers.ts

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@pi0
pi0 merged commit 50becb0 into unjs:main Jul 26, 2026
4 of 6 checks passed
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