@@ -36,18 +36,12 @@ function matrixRotate<I extends JimpClass>(image: I, deg: number) {
3636 throw new Error ( "Unsupported matrix rotation degree" ) ;
3737 }
3838
39- deg %= 360 ;
40-
41- if ( Math . abs ( deg ) === 0 ) {
42- // no rotation for 0, 360, -360, 720, -720, ...
43- return ;
44- }
45-
4639 const w = image . bitmap . width ;
4740 const h = image . bitmap . height ;
4841
4942 // decide which rotation angle to use
5043 let angle ;
44+
5145 switch ( deg ) {
5246 // 90 degree & -270 degree are same
5347 case 90 :
@@ -126,7 +120,6 @@ function advancedRotate<I extends JimpClass>(
126120 deg : number ,
127121 mode : boolean | ResizeStrategy
128122) {
129- deg %= 360 ;
130123 const rad = ( deg * Math . PI ) / 180 ;
131124 const cosine = Math . cos ( rad ) ;
132125 const sine = Math . sin ( rad ) ;
@@ -235,8 +228,17 @@ export const methods = {
235228 */
236229 rotate < I extends JimpClass > ( image : I , options : RotateOptions ) {
237230 const parsed = RotateOptionsSchema . parse ( options ) ;
238- const { deg, mode = true } =
231+ let { deg, mode = true } =
239232 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+
240242 // use matrixRotate if the angle is a multiple of 90 degrees (eg: 180 or -90) and resize is allowed or not needed.
241243 const matrixRotateAllowed =
242244 deg % 90 === 0 &&
0 commit comments