fix: crop images to their full content and skip ones with nothing to crop [patch] - #201
Merged
Merged
Conversation
…crop [patch] `image process` computed the content bounds as `right - left` and `bottom - top`, but right and bottom are inclusive pixel indices, so every image lost its last content column and row. A fully transparent image produced a negative width and a single opaque pixel a zero width; both made Crop throw an ArgumentOutOfRangeException that escaped ProcessAsync and abandoned the rest of the batch. The bounds are now inclusive, an image with no opaque pixel is skipped with a warning, and an ArgumentException from one file skips that file instead of ending the run. The loaded image is also disposed. Fixes #191 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01K185jro9zvzU5FDUdf5mWj
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Fixes #191
Problem
ImageService.RecolorAndFindBoundscomputed the content size asright - leftandbottom - top.rightandbottomare inclusive pixel indices, which caused three problems:CropthrewArgumentOutOfRangeException.Cropthrew the same exception.ProcessFileWithErrorHandlingcaught only ImageSharp's exceptions, so either throw escapedProcessAsyncand the rest of the batch was never processed.Fix
right - left + 1andbottom - top + 1.RecolorAndFindBoundsreturnsnullwhen no pixel is opaque. That file is skipped with a yellow warning.ProcessFileWithErrorHandlingalso catchesArgumentExceptionfor each file, for example padding the content can't fit. One bad file is skipped and the batch carries on.Image<Rgba32>is now disposed.Not changed here: the side issue from the report. Output keeps the input's extension but always holds PNG bytes. Switching to a
.pngextension could makefoo.jpgandfoo.pngoverwrite each other, so it needs a decision on naming and is best done separately.Tests
These are new in
ImageServiceTestsand run end-to-end throughProcessAsyncon generated PNGs:All three failed before the fix. The full suite passes: 273 of 273.
🤖 Generated with Claude Code
https://claude.ai/code/session_01K185jro9zvzU5FDUdf5mWj
Generated by Claude Code