File tree Expand file tree Collapse file tree 1 file changed +54
-18
lines changed Expand file tree Collapse file tree 1 file changed +54
-18
lines changed Original file line number Diff line number Diff line change 242
242
}
243
243
}
244
244
if ( useCanvas ) {
245
- canvas . width = destWidth ;
246
- canvas . height = destHeight ;
247
- loadImage . transformCoordinates (
248
- canvas ,
249
- options
250
- ) ;
251
- return loadImage . renderImageToCanvas (
252
- canvas ,
253
- img ,
254
- sourceX ,
255
- sourceY ,
256
- sourceWidth ,
257
- sourceHeight ,
258
- 0 ,
259
- 0 ,
260
- destWidth ,
261
- destHeight
262
- ) ;
245
+ if ( destWidth < sourceWidth && destHeight < sourceHeight ) {
246
+ var stepScale = 0.5 ;
247
+ canvas . width = sourceWidth ;
248
+ canvas . height = sourceHeight ;
249
+
250
+ while ( canvas . width > destWidth ) {
251
+ if ( canvas . width * stepScale > destWidth ) {
252
+ canvas . width = canvas . width * stepScale ;
253
+ canvas . height = canvas . height * stepScale ;
254
+ } else {
255
+ canvas . width = destWidth ;
256
+ canvas . height = destHeight ;
257
+ }
258
+ loadImage . transformCoordinates (
259
+ canvas ,
260
+ options
261
+ ) ;
262
+ canvas = loadImage . renderImageToCanvas (
263
+ canvas ,
264
+ img ,
265
+ sourceX ,
266
+ sourceY ,
267
+ sourceWidth ,
268
+ sourceHeight ,
269
+ 0 ,
270
+ 0 ,
271
+ canvas . width ,
272
+ canvas . height
273
+ ) ;
274
+ img = new Image ( ) ;
275
+ img . src = canvas . toDataURL ( ) ;
276
+ sourceWidth = canvas . width ;
277
+ sourceHeight = canvas . height ;
278
+ }
279
+ } else {
280
+ canvas . width = destWidth ;
281
+ canvas . height = destHeight ;
282
+ loadImage . transformCoordinates (
283
+ canvas ,
284
+ options
285
+ ) ;
286
+ return loadImage . renderImageToCanvas (
287
+ canvas ,
288
+ img ,
289
+ sourceX ,
290
+ sourceY ,
291
+ sourceWidth ,
292
+ sourceHeight ,
293
+ 0 ,
294
+ 0 ,
295
+ destWidth ,
296
+ destHeight
297
+ ) ;
298
+ }
263
299
}
264
300
img . width = destWidth ;
265
301
img . height = destHeight ;
You can’t perform that action at this time.
0 commit comments