Преглед изворни кода

Set image width / height if image has no dimension

https://youtrack.weseek.co.jp/issue/GW-7894
- Set image width & height by natural width & height if image has no width and height
Mudana-Grune пре 3 година
родитељ
комит
2c43aebcee
1 измењених фајлова са 5 додато и 6 уклоњено
  1. 5 6
      packages/app/src/components/Common/ImageCropModal.tsx

+ 5 - 6
packages/app/src/components/Common/ImageCropModal.tsx

@@ -51,12 +51,11 @@ const ImageCropModal: FC<Props> = (props: Props) => {
     if (imageRef) {
       // Some SVG files may not have width and height properties, causing the render size to be 0x0
       // Force imageRef to have width and height by create temporary image element then set the imageRef width with tempImage width
-      // const tempImage = new Image();
-      // tempImage.src = imageRef.src;
-      // imageRef.width = tempImage.width;
-      if (imageRef.width == null) { imageRef.width = 0 }
-      if (imageRef.height == null) { imageRef.height = 0 }
-
+      // Set imageRef width & height by natural width / height if image has no dimension
+      if (imageRef.width === 0 || imageRef.height === 0) {
+        imageRef.width = imageRef.naturalWidth;
+        imageRef.height = imageRef.naturalHeight;
+      }
       // Get size of Image, min value of width and height
       const size = Math.min(imageRef.width, imageRef.height);
       setCropOtions({