File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -188,8 +188,10 @@ class PipelineWorker : public Napi::AsyncWorker {
188188 if (jpegShrinkOnLoad > 1 && static_cast <int >(shrink) == jpegShrinkOnLoad) {
189189 jpegShrinkOnLoad /= 2 ;
190190 }
191- } else if (inputImageType == sharp::ImageType::WEBP ||
192- inputImageType == sharp::ImageType::SVG ||
191+ } else if (inputImageType == sharp::ImageType::WEBP && shrink > 1.0 ) {
192+ // Avoid upscaling via webp
193+ scale = 1.0 / shrink;
194+ } else if (inputImageType == sharp::ImageType::SVG ||
193195 inputImageType == sharp::ImageType::PDF) {
194196 scale = 1.0 / shrink;
195197 }
Original file line number Diff line number Diff line change @@ -121,6 +121,20 @@ describe('Resize dimensions', function () {
121121 } ) ;
122122 } ) ;
123123
124+ it ( 'Webp resize then extract large image' , function ( done ) {
125+ sharp ( fixtures . inputWebP )
126+ . resize ( 0x4000 , 0x4000 )
127+ . extract ( { top : 0x2000 , left : 0x2000 , width : 256 , height : 256 } )
128+ . webp ( )
129+ . toBuffer ( function ( err , data , info ) {
130+ if ( err ) throw err ;
131+ assert . strictEqual ( 'webp' , info . format ) ;
132+ assert . strictEqual ( 256 , info . width ) ;
133+ assert . strictEqual ( 256 , info . height ) ;
134+ done ( ) ;
135+ } ) ;
136+ } ) ;
137+
124138 it ( 'WebP shrink-on-load rounds to zero, ensure recalculation is correct' , function ( done ) {
125139 sharp ( fixtures . inputJpg )
126140 . resize ( 1080 , 607 )
You can’t perform that action at this time.
0 commit comments