@@ -46,15 +46,17 @@ const constructRect = (box: Box): Rect => {
46
46
} ;
47
47
48
48
const getContainedSize = ( img : HTMLCanvasElement ) : Box => {
49
+ const imgClientHeight = img . clientHeight ;
50
+ const imgClientWidth = img . clientWidth ;
49
51
const ratio = img . width / img . height ;
50
- let width = img . clientHeight * ratio ;
51
- let height = img . clientHeight ;
52
- if ( width > img . clientWidth ) {
53
- width = img . clientWidth ;
54
- height = img . clientWidth / ratio ;
52
+ let width = imgClientHeight * ratio ;
53
+ let height = imgClientHeight ;
54
+ if ( width > imgClientWidth ) {
55
+ width = imgClientWidth ;
56
+ height = imgClientWidth / ratio ;
55
57
}
56
- const x = ( img . clientWidth - width ) / 2 ;
57
- const y = ( img . clientHeight - height ) / 2 ;
58
+ const x = ( imgClientWidth - width ) / 2 ;
59
+ const y = ( imgClientHeight - height ) / 2 ;
58
60
return { startX : x , startY : y , endX : width + x , endY : height + y } ;
59
61
} ;
60
62
@@ -215,9 +217,11 @@ export function makeScreenshotEditorComponent({ h, imageBuffer, dialog }: Factor
215
217
if ( ! context ) {
216
218
throw new Error ( 'Could not get canvas context' ) ;
217
219
}
218
- imageBuffer . width = imageSource . videoWidth ;
219
- imageBuffer . height = imageSource . videoHeight ;
220
- context . drawImage ( imageSource , 0 , 0 , imageSource . videoWidth , imageSource . videoHeight ) ;
220
+ const sourceWidth = imageSource . videoWidth ;
221
+ const sourceHeight = imageSource . videoHeight ;
222
+ imageBuffer . width = sourceWidth ;
223
+ imageBuffer . height = sourceHeight ;
224
+ context . drawImage ( imageSource , 0 , 0 , sourceWidth , sourceHeight ) ;
221
225
} ,
222
226
[ imageBuffer ] ,
223
227
) ,
0 commit comments