Skip to content

fix(image): keep derived crop sides at least one pixel - #14828

Merged
ChiragAgg5k merged 1 commit into
mainfrom
fix/image-crop-zero-dimension
Oct 22, 2026
Merged

ChiragAgg5k merged 1 commit into
mainfrom
fix/image-crop-zero-dimension

Conversation

@ChiragAgg5k

@ChiragAgg5k ChiragAgg5k commented Oct 22, 2026 •

Copy link
Copy Markdown
Member

Summary

When only one side is passed, Utopia\Image\Image::crop() derives the other from the source aspect ratio and rounds down. A 1px side on a skewed source (for example width=1, height=0 on a landscape image) derived 0: with non-center gravity that divided by zero, otherwise Imagick got an empty geometry. The storage preview endpoint answered 500 for those params.

The derived side is now clamped to at least 1px, and the "both sides 0" case is checked first so it still falls back to the source size. The preview endpoint returns a valid image for these params.

Test plan

  • bin/monorepo check image and bin/monorepo test image; new data-provider test covers landscape and portrait sources with 1px sides across gravities (three cases throw DivisionByZeroError without the fix)
  • E2E testFilePreviewOnePixelSideWithGravity: preview of a landscape JPEG with width=1, height=0, gravity=top-left returns 200 and a 1x1 PNG

Related: appwrite-labs/cloud#5938

When only one side is given, crop() derives the other from the source aspect ratio and rounds down. A 1px side on a skewed source derived 0, which then divided by zero for non-center gravity and reached Imagick as an empty geometry otherwise, so the storage preview answered 500. The derived side is now clamped to 1.
@luxor-code-review

luxor-code-review Bot commented Oct 22, 2026 •

Copy link
Copy Markdown

Review complete. No issues found — approved ✅.


This PR introduces a gravity-based crop transformation (top/center/bottom variants) in the image package, wired into the storage preview pipeline with Imagick and GD support.

Files Change
packages/image/src/Image.php Adds the gravity-dependent crop math and adapter calls to the Image transform API.
packages/image/tests/ImageTest.php Adds unit coverage for the new crop behavior across dimensions and gravity values.
tests/e2e/Services/Storage/StorageBase.php Extends the storage e2e suite to exercise the crop through the preview endpoint.

Reviewed commit: c310aa5

@ChiragAgg5k ChiragAgg5k self-assigned this Oct 22, 2026
@ghost

ghost commented Oct 22, 2026 •

Copy link
Copy Markdown

🟢 Tier S · Ready to merge

The dimension derivation and both-zero fallback are covered by the new and existing tests, with no defect found in the changed paths.

Updated Image::crop() to clamp a derived crop side to at least one pixel while preserving the original-size fallback when both dimensions are zero. Added package-level crop coverage across landscape and portrait inputs and an end-to-end storage preview case for a one-pixel crop with non-center gravity.

Verdict New comments Fixed Still open
✅ Approved 0 0 0
📂 Walkthrough · 3
File Change
packages/image/src/Image.php Clamps a derived crop dimension to at least one pixel and checks the both-zero fallback first.
packages/image/tests/ImageTest.php Adds data-provider coverage for derived one-pixel crop dimensions across source aspect ratios and gravities.
tests/e2e/Services/Storage/StorageBase.php Adds an end-to-end storage preview test for a one-pixel crop with non-center gravity.

Reviewed c310aa5 · Details · Comment @hansi-codes review to re-run, or mention @hansi-codes with a question.

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

🟢 Tier S · Looks good to merge. Summary

@github-actions

Copy link
Copy Markdown

✨ Benchmark results

Comparing main (before) → fix/image-crop-zero-dimension (after).

Metric Before After Change
🚀 Requests/sec 211 214.13 ⚪ +1.5%
⏱️ Latency P50 81.2 ms 80.42 ms ⚪ -1%
⏱️ Latency P95 188.62 ms 191.11 ms ⚪ +1.3%
Per-scenario breakdown & investigation details

Metrics below reflect the current branch (after). Δ P95 compares against the base.

Scenario P50 (ms) P95 (ms) Requests RPS Δ P95 (ms)
API total 80.42 191.11 13,680 214.13 +2.49
Account 146.45 288.47 720 11.93 +15.32
TablesDB 77.06 140.86 7,440 118.49 -1.08
Storage 75.76 184.96 3,600 59.27 -7.18
Functions 114.66 232.08 1,920 32.35 +12.45

Top API waits (after)

API request Max wait (ms)
functions.variables.update 462.26
account.name.update 446.09
account.prefs.update 405.77
functions.create 389.61
functions.variables.create 360.63

@github-actions

Copy link
Copy Markdown

Security rules

No new WARNING or ERROR findings from security rules.

6 existing findings tracked in .semgrep/baseline.json
  • php.appwrite.guest-write-without-abuse-limit (3)
  • php.appwrite.secret-compare-timing (1)
  • php.appwrite.weak-secret-env-default (2)

Posted by Checks / Rules. Re-runs update this comment in place. Rule details and baseline: .semgrep/README.md.

@ChiragAgg5k
ChiragAgg5k merged commit b2a765f into main Oct 22, 2026
69 checks passed
@ChiragAgg5k
ChiragAgg5k deleted the fix/image-crop-zero-dimension branch October 22, 2026 17:06
Tapraj-Pathak pushed a commit to Tapraj-Pathak/appwrite that referenced this pull request Oct 24, 2026
…imension

fix(image): keep derived crop sides at least one pixel

(cherry picked from commit b2a765f)
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.

1 participant