Commit 3282c2d
committed
fix: rotate slow path clipped content by keeping canvas at input size
The rotate slow path on iOS (NativeImage.swift) and Android
(HybridImage.kt) sized the output canvas to the input image's
dimensions. When degrees is not a multiple of 180 (e.g., a 90 degree
rotation of a portrait image into a landscape), the rotated content
extends beyond the canvas and gets clipped -- the caller sees an image
at the input dimensions with half the rotated content missing.
Fix: compute the rotated bounding box as
outputW = abs(cos(r)) * w + abs(sin(r)) * h
outputH = abs(sin(r)) * w + abs(cos(r)) * h
Size the renderer / destination bitmap to that, then translate so the
rotated content lands centered on the output canvas.
Verified end-to-end on iPhone 15 Pro (3x) and a Pixel-class Android
device via a vision-camera v5 photo-scanning app: rotating a portrait
card 90 degrees now produces a correctly sized landscape JPEG with
complete content, rather than a portrait JPEG with a clipped landscape
rectangle inside.
Works for any angle (the cos/sin formula gives a tight bounding box for
arbitrary rotations), but the bug is most visible at 90/270 where the
canvas is transposed from the content.1 parent 7bec013 commit 3282c2d
2 files changed
Lines changed: 40 additions & 15 deletions
File tree
- packages/react-native-nitro-image
- android/src/main/java/com/margelo/nitro/image
- ios/Public
Lines changed: 20 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
82 | 82 | | |
83 | 83 | | |
84 | 84 | | |
85 | | - | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
86 | 99 | | |
87 | 100 | | |
88 | | - | |
89 | | - | |
90 | | - | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
91 | 107 | | |
92 | 108 | | |
93 | 109 | | |
94 | | - | |
95 | 110 | | |
96 | 111 | | |
97 | 112 | | |
| |||
Lines changed: 20 additions & 10 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
63 | 63 | | |
64 | 64 | | |
65 | 65 | | |
66 | | - | |
67 | | - | |
68 | | - | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
69 | 80 | | |
70 | 81 | | |
71 | | - | |
| 82 | + | |
72 | 83 | | |
73 | | - | |
74 | | - | |
75 | | - | |
76 | | - | |
| 84 | + | |
| 85 | + | |
77 | 86 | | |
78 | | - | |
79 | 87 | | |
80 | | - | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
81 | 91 | | |
82 | 92 | | |
83 | 93 | | |
| |||
0 commit comments