@@ -46,15 +46,17 @@ const constructRect = (box: Box): Rect => {
4646} ;
4747
4848const getContainedSize = ( img : HTMLCanvasElement ) : Box => {
49+ const imgClientHeight = img . clientHeight ;
50+ const imgClientWidth = img . clientWidth ;
4951 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 ;
5557 }
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 ;
5860 return { startX : x , startY : y , endX : width + x , endY : height + y } ;
5961} ;
6062
@@ -215,9 +217,11 @@ export function makeScreenshotEditorComponent({ h, imageBuffer, dialog }: Factor
215217 if ( ! context ) {
216218 throw new Error ( 'Could not get canvas context' ) ;
217219 }
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 ) ;
221225 } ,
222226 [ imageBuffer ] ,
223227 ) ,
0 commit comments