Skip to content

Commit

Permalink
Use image-rendering: auto when downscaling images (#3144)
Browse files Browse the repository at this point in the history
  • Loading branch information
casey authored Feb 19, 2024
1 parent e40bcd1 commit cf02bb8
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
15 changes: 15 additions & 0 deletions static/preview-image.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
function resize() {
if (
body.clientWidth * window.devicePixelRatio < img.naturalWidth
|| body.clientHeight * window.devicePixelRatio < img.naturalHeight
) {
body.style.imageRendering = 'auto';
} else {
body.removeAttribute('style');
}
}

let body = document.body;
let img = document.getElementsByTagName('img')[0];

(new ResizeObserver(resize)).observe(body);
1 change: 1 addition & 0 deletions templates/preview-image.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
width: 100%;
}
</style>
<script src=/static/preview-image.js type=module defer></script>
</head>
<body>
<img src=/content/{{self.inscription_id}}></img>
Expand Down

0 comments on commit cf02bb8

Please sign in to comment.