Skip to content

Commit

Permalink
Merge pull request #927 from revolunet/issue-250
Browse files Browse the repository at this point in the history
fix(content-scanning): use devicePixelRatio in thumbnails dimensions
  • Loading branch information
estellecomment authored Mar 5, 2024
2 parents 75cf955 + fed14b9 commit 1a913a5
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/tchap/customisations/ContentScanningMedia.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,9 @@ export class Media {
*/
public getThumbnailHttp(width: number, height: number, mode: ResizeMethod = "scale"): string | null | undefined {
if (!this.hasThumbnail) return null;
// scale using the device pixel ratio to keep images clear
width = Math.floor(width * window.devicePixelRatio);
height = Math.floor(height * window.devicePixelRatio);
return ContentScanner.instance.urlForMxc(this.thumbnailMxc, width, height, mode);
}

Expand All @@ -99,6 +102,9 @@ export class Media {
* @returns {string} The HTTP URL which points to the thumbnail.
*/
public getThumbnailOfSourceHttp(width: number, height: number, mode: ResizeMethod = "scale"): string {
// scale using the device pixel ratio to keep images clear
width = Math.floor(width * window.devicePixelRatio);
height = Math.floor(height * window.devicePixelRatio);
return ContentScanner.instance.urlForMxc(this.srcMxc, width, height, mode);
}

Expand All @@ -109,6 +115,7 @@ export class Media {
* @returns {string} An HTTP URL for the thumbnail.
*/
public getSquareThumbnailHttp(dim: number): string {
dim = Math.floor(dim * window.devicePixelRatio); // scale using the device pixel ratio to keep images clear
if (this.hasThumbnail) {
return this.getThumbnailHttp(dim, dim, "crop");
}
Expand Down

0 comments on commit 1a913a5

Please sign in to comment.