File tree Expand file tree Collapse file tree 1 file changed +4
-3
lines changed Expand file tree Collapse file tree 1 file changed +4
-3
lines changed Original file line number Diff line number Diff line change 204
204
205
205
if (! imageWidth || ! imageHeight || ! containerWidth || ! containerHeight) return {};
206
206
207
- const vertical = imageWidth / imageHeight < 1 ;
207
+ const imageAspectRatio = imageWidth / imageHeight;
208
+ const containerAspectRatio = containerWidth / containerHeight;
208
209
209
210
if (fit === ObjectFit .SCALE_DOWN ) {
210
211
const isSmaller = imageWidth < containerWidth && imageHeight < containerHeight;
215
216
case ObjectFit .NONE :
216
217
return { width: ' auto' , height: ' auto' };
217
218
case ObjectFit .CONTAIN :
218
- return vertical ? { width: ' auto' } : { height: ' auto' };
219
+ return (imageAspectRatio < containerAspectRatio) ? { width: ' auto' } : { height: ' auto' };
219
220
case ObjectFit .COVER :
220
- return vertical ? { height: ' auto' } : { width: ' auto' };
221
+ return (imageAspectRatio < containerAspectRatio) ? { height: ' auto' } : { width: ' auto' };
221
222
default :
222
223
return {};
223
224
}
You can’t perform that action at this time.
0 commit comments