params['ptStyle']; if ($style == 2) { return Yii::$app->params['ghsImgHost']; } elseif ($style == 1) { return Yii::$app->params['hdImgHost']; } elseif ($style == 3) { return Yii::$app->params['mallImgHost']; } else { return Yii::$app->params['hdImgHost']; } } //组合出图片路径 ssh 2021.4.9 public static function groupImg($pic) { $prefix = self::getPrefix(); if (empty($pic)) { return $prefix . 'hhb_small.png'; } return $prefix . $pic; } /** * OSS 图片水印用的对象路径(桶内相对路径,不要带域名) * xhGoods.cover 常为 default-img.png,实际对象在 retail/default-img.png */ public static function normalizeOssObjectPath($pic) { $pic = trim((string)$pic); if ($pic === '') { return 'retail/default-img.png'; } if (strpos($pic, 'http://') === 0 || strpos($pic, 'https://') === 0) { $pic = ltrim(parse_url($pic, PHP_URL_PATH) ?? '', '/'); } $pic = ltrim($pic, '/'); if ($pic === 'default-img.png' || $pic === 'hhb_small.png') { return 'retail/default-img.png'; } return $pic; } /** * 通过 OSS image/info 读取图片宽高(用于海报动态画布) * * @return array{0:int,1:int} [width, height] */ public static function getOssImageSize($objectPath, $prefix = null) { $objectPath = self::normalizeOssObjectPath($objectPath); if ($prefix === null || $prefix === '') { $prefix = self::getPrefix(); } $infoUrl = rtrim($prefix, '/') . '/' . $objectPath . '?x-oss-process=image/info'; $context = stream_context_create([ 'http' => [ 'timeout' => 5, 'ignore_errors' => true, ], ]); $json = @file_get_contents($infoUrl, false, $context); if ($json === false || $json === '') { return [0, 0]; } $data = json_decode($json, true); if (!is_array($data)) { return [0, 0]; } $w = (int)($data['ImageWidth']['value'] ?? 0); $h = (int)($data['ImageHeight']['value'] ?? 0); return [$w, $h]; } }