File tree Expand file tree Collapse file tree 2 files changed +23
-5
lines changed
Expand file tree Collapse file tree 2 files changed +23
-5
lines changed Original file line number Diff line number Diff line change 225225 if ( useCanvas ) {
226226 pixelRatio = options . pixelRatio
227227 if ( pixelRatio > 1 ) {
228- canvas . style . width = destWidth + 'px'
229- canvas . style . height = destHeight + 'px'
230- destWidth *= pixelRatio
231- destHeight *= pixelRatio
232- canvas . getContext ( '2d' ) . scale ( pixelRatio , pixelRatio )
228+ if ( parseInt ( img . style . width , 10 ) === width / pixelRatio ) {
229+ // Source image is already scaled according to device pixel ratio
230+ canvas . style . width = destWidth / pixelRatio + 'px'
231+ canvas . style . height = destHeight / pixelRatio + 'px'
232+ } else {
233+ canvas . style . width = destWidth + 'px'
234+ canvas . style . height = destHeight + 'px'
235+ destWidth *= pixelRatio
236+ destHeight *= pixelRatio
237+ canvas . getContext ( '2d' ) . scale ( pixelRatio , pixelRatio )
238+ }
233239 }
234240 downsamplingRatio = options . downsamplingRatio
235241 if (
Original file line number Diff line number Diff line change 300300 expect ( img . height ) . to . equal ( 160 )
301301 expect ( img . style . width ) . to . equal ( '120px' )
302302 expect ( img . style . height ) . to . equal ( '80px' )
303+ // Check if pixelRatio scaling is idempotent:
304+ var img2 = loadImage . scale ( img , { minWidth : 120 , pixelRatio : 2 } )
305+ expect ( img2 . width ) . to . equal ( 240 )
306+ expect ( img2 . height ) . to . equal ( 160 )
307+ expect ( img2 . style . width ) . to . equal ( '120px' )
308+ expect ( img2 . style . height ) . to . equal ( '80px' )
303309 done ( )
304310 } ,
305311 { minWidth : 120 , canvas : true , pixelRatio : 2 }
316322 expect ( img . height ) . to . equal ( 40 )
317323 expect ( img . style . width ) . to . equal ( '30px' )
318324 expect ( img . style . height ) . to . equal ( '20px' )
325+ // Check if pixelRatio scaling is idempotent:
326+ var img2 = loadImage . scale ( img , { minWidth : 30 , pixelRatio : 2 } )
327+ expect ( img2 . width ) . to . equal ( 60 )
328+ expect ( img2 . height ) . to . equal ( 40 )
329+ expect ( img2 . style . width ) . to . equal ( '30px' )
330+ expect ( img2 . style . height ) . to . equal ( '20px' )
319331 done ( )
320332 } ,
321333 { maxWidth : 30 , canvas : true , pixelRatio : 2 }
You can’t perform that action at this time.
0 commit comments