@@ -189,7 +189,7 @@ export class WatermarkAction extends BaseImageAction {
189
189
const textOpt = this . calculateTextSize ( opt . text , opt . size ) ;
190
190
const svg = this . textSvgStr ( opt , textOpt , true , opt . shadow / 100 ) ;
191
191
const svgBytes = Buffer . from ( svg ) ;
192
- const metadata = await ctx . image . metadata ( ) ;
192
+ const metadata = withNormalSize ( ctx . metadata ) ;
193
193
if ( 0 < opt . rotate ) {
194
194
// hard to rotate the svg directly, so attach it on image, then rotate the image
195
195
const overlapImg = this . textSvgImg ( svgBytes , textOpt ) ;
@@ -234,7 +234,7 @@ export class WatermarkAction extends BaseImageAction {
234
234
watermarkImg = sharp ( bt ) ;
235
235
}
236
236
// auto scale warkmark size
237
- const metadata = await ctx . image . metadata ( ) ;
237
+ const metadata = withNormalSize ( ctx . metadata ) ;
238
238
const markMetadata = await watermarkImg . metadata ( ) ;
239
239
if ( opt . auto ) {
240
240
// check the warkmark image size, if bigger than backgroud image, need resize the overlay
@@ -276,7 +276,7 @@ export class WatermarkAction extends BaseImageAction {
276
276
const gravityOpt = this . calculateMixedGravity ( opt ) ;
277
277
const wbt = await watermarkImg . toBuffer ( ) ;
278
278
279
- const metadata = await ctx . image . metadata ( ) ;
279
+ const metadata = withNormalSize ( ctx . metadata ) ;
280
280
281
281
const expectedWidth = textOpt . width + imgW + opt . interval ;
282
282
const expectedHeight = Math . max ( textOpt . height , imgH ) ;
@@ -452,7 +452,7 @@ export class WatermarkAction extends BaseImageAction {
452
452
let h = textOpt . height ;
453
453
let needResize = false ;
454
454
const overlapImgMeta = await source . metadata ( ) ;
455
- const metadata = await ctx . image . metadata ( ) ;
455
+ const metadata = withNormalSize ( ctx . metadata ) ;
456
456
457
457
if ( overlapImgMeta . width && metadata . width && overlapImgMeta . width > metadata . width ) {
458
458
w = metadata . width - 10 ;
@@ -523,3 +523,12 @@ export class WatermarkAction extends BaseImageAction {
523
523
return overlay ;
524
524
}
525
525
}
526
+
527
+ function withNormalSize ( metadata : sharp . Metadata ) : sharp . Metadata {
528
+ const o = Object . assign ( { } , metadata ) ;
529
+ if ( ( metadata . orientation || 0 ) >= 5 ) {
530
+ o . width = o . height ;
531
+ o . height = o . width ;
532
+ }
533
+ return o ;
534
+ }
0 commit comments