defaultFontPath; } /** * 获得随机图片 * @param $images * @return string */ protected function getRandImage($images): string { $index = RandomUtils::getRandomInt(0, count($images) - 1); return $images[$index]; } /** * 获取默认图片 * @param $dir * @param $images * @return array|false */ protected function getDefaultImage($dir, $images) { if (!empty($images)) { if (is_array($images)) { return $images; } if (is_string($images)) { $dir = $images; } } return glob($dir . '*.png'); } /** * 获取一张背景图地址 * @param null $backgrounds 背景图库 * @return BackgroundVo */ public function getBackgroundVo($backgrounds = null): BackgroundVo { $dir = dirname(__DIR__, 3). $this->defaultBackgroundPath; $backgrounds = $this->getDefaultImage($dir, $backgrounds); $src = $this->getRandImage($backgrounds); return new BackgroundVo($src); } }