@@ -36,18 +36,12 @@ function matrixRotate<I extends JimpClass>(image: I, deg: number) {
36
36
throw new Error ( "Unsupported matrix rotation degree" ) ;
37
37
}
38
38
39
- deg %= 360 ;
40
-
41
- if ( Math . abs ( deg ) === 0 ) {
42
- // no rotation for 0, 360, -360, 720, -720, ...
43
- return ;
44
- }
45
-
46
39
const w = image . bitmap . width ;
47
40
const h = image . bitmap . height ;
48
41
49
42
// decide which rotation angle to use
50
43
let angle ;
44
+
51
45
switch ( deg ) {
52
46
// 90 degree & -270 degree are same
53
47
case 90 :
@@ -126,7 +120,6 @@ function advancedRotate<I extends JimpClass>(
126
120
deg : number ,
127
121
mode : boolean | ResizeStrategy
128
122
) {
129
- deg %= 360 ;
130
123
const rad = ( deg * Math . PI ) / 180 ;
131
124
const cosine = Math . cos ( rad ) ;
132
125
const sine = Math . sin ( rad ) ;
@@ -235,8 +228,17 @@ export const methods = {
235
228
*/
236
229
rotate < I extends JimpClass > ( image : I , options : RotateOptions ) {
237
230
const parsed = RotateOptionsSchema . parse ( options ) ;
238
- const { deg, mode = true } =
231
+ let { deg, mode = true } =
239
232
typeof parsed === "number" ? { deg : parsed } : parsed ;
233
+
234
+ // No need to do extra rotation
235
+ deg %= 360 ;
236
+
237
+ // no rotation for 0, 360, -360, 720, -720, ...
238
+ if ( deg % 360 === 0 ) {
239
+ return image ;
240
+ }
241
+
240
242
// use matrixRotate if the angle is a multiple of 90 degrees (eg: 180 or -90) and resize is allowed or not needed.
241
243
const matrixRotateAllowed =
242
244
deg % 90 === 0 &&
0 commit comments