فهرست منبع

Merge pull request #3121 from inthreedee/patch-1

Avoid upscaling small images
daniel 3 سال پیش
والد
کامیت
854f858543
1فایلهای تغییر یافته به همراه10 افزوده شده و 3 حذف شده
  1. 10 3
      app/Util/Media/Image.php

+ 10 - 3
app/Util/Media/Image.php

@@ -72,6 +72,8 @@ class Image
 		return [
 		return [
 			'dimensions'  => $this->orientations()[$orientation],
 			'dimensions'  => $this->orientations()[$orientation],
 			'orientation' => $orientation,
 			'orientation' => $orientation,
+			'width_original' => $width,
+			'height_original' => $height,
 		];
 		];
 	}
 	}
 
 
@@ -157,9 +159,14 @@ class Image
 					$media->metadata = json_encode($meta);
 					$media->metadata = json_encode($meta);
 				}
 				}
 
 
-				$img->resize($aspect['width'], $aspect['height'], function ($constraint) {
-					$constraint->aspectRatio();
-				});
+				if (
+				    ($ratio['width_original'] > $aspect['width'])
+				    || ($ratio['height_original'] > $aspect['height'])
+				) {
+					$img->resize($aspect['width'], $aspect['height'], function ($constraint) {
+						$constraint->aspectRatio();
+					});
+				}
 			}
 			}
 			$converted = $this->setBaseName($path, $thumbnail, $img->extension);
 			$converted = $this->setBaseName($path, $thumbnail, $img->extension);
 			$newPath = storage_path('app/'.$converted['path']);
 			$newPath = storage_path('app/'.$converted['path']);