You've already forked matrix-react-sdk
							
							
				mirror of
				https://github.com/matrix-org/matrix-react-sdk.git
				synced 2025-11-03 00:33:22 +03:00 
			
		
		
		
	Improve image drawing fill strategy
This commit is contained in:
		@@ -37,16 +37,28 @@ export default class BackdropPanel extends React.PureComponent<IProps> {
 | 
				
			|||||||
        const imageHeight = (backgroundImage as ImageBitmap).height
 | 
					        const imageHeight = (backgroundImage as ImageBitmap).height
 | 
				
			||||||
                || (backgroundImage as HTMLImageElement).naturalHeight;
 | 
					                || (backgroundImage as HTMLImageElement).naturalHeight;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        const destinationX = width - imageWidth;
 | 
					        const contentRatio = imageWidth / imageHeight;
 | 
				
			||||||
        const destinationY = height - imageHeight;
 | 
					        const containerRatio = width / height;
 | 
				
			||||||
 | 
					        let resultHeight;
 | 
				
			||||||
 | 
					        let resultWidth;
 | 
				
			||||||
 | 
					        if (contentRatio > containerRatio) {
 | 
				
			||||||
 | 
					            resultHeight = height;
 | 
				
			||||||
 | 
					            resultWidth = height * contentRatio;
 | 
				
			||||||
 | 
					        } else {
 | 
				
			||||||
 | 
					            resultWidth = width;
 | 
				
			||||||
 | 
					            resultHeight = width / contentRatio;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        const x = (width - resultWidth) / 2;
 | 
				
			||||||
 | 
					        const y = (height - resultHeight) / 2;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        this.ctx.filter = `blur(${this.props.blur})`;
 | 
					        this.ctx.filter = `blur(${this.props.blur})`;
 | 
				
			||||||
        this.ctx.drawImage(
 | 
					        this.ctx.drawImage(
 | 
				
			||||||
            backgroundImage,
 | 
					            backgroundImage,
 | 
				
			||||||
            Math.min(destinationX, 0),
 | 
					            x,
 | 
				
			||||||
            Math.min(destinationY, 0),
 | 
					            y,
 | 
				
			||||||
            Math.max(width, imageWidth),
 | 
					            resultWidth,
 | 
				
			||||||
            Math.max(height, imageHeight),
 | 
					            resultHeight,
 | 
				
			||||||
        );
 | 
					        );
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -61,7 +61,6 @@ import { MatrixCall } from 'matrix-js-sdk/src/webrtc/call';
 | 
				
			|||||||
import AudioFeedArrayForCall from '../views/voip/AudioFeedArrayForCall';
 | 
					import AudioFeedArrayForCall from '../views/voip/AudioFeedArrayForCall';
 | 
				
			||||||
import { OwnProfileStore } from '../../stores/OwnProfileStore';
 | 
					import { OwnProfileStore } from '../../stores/OwnProfileStore';
 | 
				
			||||||
import { UPDATE_EVENT } from "../../stores/AsyncStore";
 | 
					import { UPDATE_EVENT } from "../../stores/AsyncStore";
 | 
				
			||||||
import { mediaFromMxc } from "../../customisations/Media";
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// We need to fetch each pinned message individually (if we don't already have it)
 | 
					// We need to fetch each pinned message individually (if we don't already have it)
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user