Ver Fonte

fixed computing of natural size

Gildas há 7 anos atrás
pai
commit
11bd3e700f
1 ficheiros alterados com 12 adições e 2 exclusões
  1. 12 2
      lib/single-file/doc-helper.js

+ 12 - 2
lib/single-file/doc-helper.js

@@ -223,11 +223,21 @@ this.docHelper = this.docHelper || (() => {
 					imageElement = element;
 				}
 				if (imageElement) {
+					let naturalWidth = imageElement.naturalWidth;
+					let naturalHeight = imageElement.naturalHeight;
+					if (naturalWidth <= 1 && naturalHeight <= 1) {
+						const imgElement = doc.createElement("img");
+						imgElement.src = imageElement.src;
+						doc.body.appendChild(imgElement);
+						naturalWidth = imgElement.width;
+						naturalHeight = imgElement.height;
+						imgElement.remove();
+					}
 					imageData.source = {
 						clientWidth: imageElement.clientWidth,
 						clientHeight: imageElement.clientHeight,
-						naturalWidth: imageElement.naturalWidth,
-						naturalHeight: imageElement.naturalHeight,
+						naturalWidth: naturalWidth,
+						naturalHeight: naturalHeight,
 						width: imageElement.width,
 						height: imageElement.height,
 						src: (!imageElement.currentSrc.startsWith("data:") && imageElement.currentSrc) || (!imageElement.src.startsWith("data:") && imageElement.src)