mirror of
https://github.com/diced/zipline.git
synced 2025-04-11 23:31:17 -05:00
fix: small images resizing for no reason
This commit is contained in:
parent
48cfa41405
commit
58a4580cf0
1 changed files with 7 additions and 2 deletions
|
@ -64,9 +64,14 @@ export default function EmbeddedFile({
|
|||
|
||||
const img = new Image();
|
||||
img.addEventListener('load', function () {
|
||||
// my best attempt of recreating https://searchfox.org/mozilla-central/source/dom/html/ImageDocument.cpp#271-276
|
||||
// and it actually works
|
||||
// my best attempt of recreating
|
||||
// firefox: https://searchfox.org/mozilla-central/source/dom/html/ImageDocument.cpp#271-276
|
||||
// chromium-based: https://source.chromium.org/chromium/chromium/src/+/main:third_party/blink/renderer/core/html/image_document.cc
|
||||
|
||||
// keeps image original if smaller than screen
|
||||
if (this.width <= window.innerWidth && this.height <= window.innerHeight) return;
|
||||
|
||||
// resizes to fit screen
|
||||
const ratio = Math.min(innerHeight / this.naturalHeight, innerWidth / this.naturalWidth);
|
||||
const newWidth = Math.max(1, Math.floor(ratio * this.naturalWidth));
|
||||
const newHeight = Math.max(1, Math.floor(ratio * this.naturalHeight));
|
||||
|
|
Loading…
Add table
Reference in a new issue