Bladeren bron

商品多款式图片兼容旧系统

shish 6 jaren geleden
bovenliggende
commit
6cb34cb8d5
1 gewijzigde bestanden met toevoegingen van 20 en 0 verwijderingen
  1. 20 0
      common/components/business.php

+ 20 - 0
common/components/business.php

@@ -97,6 +97,26 @@ class business
 		$prefixImgUrl = Yii::$app->params['imgHost'];
 		$smallImg = self::getSmallImg($imgUrl);
 		$small = $prefixImgUrl . $smallImg;
+
+
+		//没有小图的生成小图(兼容旧系统) shish 2020.6.4
+		$imageRoot = dirUtil::getImgUploadDir();
+		$preImg = $imageRoot . str_replace('/uploads', '', $imgUrl);
+		if (file_exists($preImg)) {
+			//没有小图则生成小图,兼容旧系统
+			if (file_exists($imageRoot . $smallImg) == false) {
+				$imgInfo = getimagesize($preImg);
+				$width = $imgInfo[0];
+				$height = $imgInfo[1];
+				//生成小图 300px
+				$smallWidth = 300;
+				$smallHeight = ceil((300 * $height) / $width);
+				$smallFullPathFile = $imageRoot . str_replace('/uploads', '', $smallImg);
+				Image::thumbnail($preImg, $smallWidth, $smallHeight)->save($smallFullPathFile, ['quality' => 100]);
+			}
+		}
+
+
 		$info['img'] = $small;
 		return $info;
 	}