text($config['upload_water_font'], $ttf, $size, $color, $config['upload_water_pos'])->save($filename); } else { if (!file_exists($config['upload_water_img'])) { return false; } $ImageWaterInfo = getimagesize($config['upload_water_img']); // 对比图片大小 if ($ImageWaterInfo[0] >= $ImageInfo[0] || $ImageWaterInfo[1] >= $ImageInfo[1]) { return false; } // 检查图片 $resWater = $Image->water($config['upload_water_img'], $config['upload_water_pos'], $config['upload_water_pct'])->save($filename); } return $resWater ?? false; } catch (\Throwable $th) { throw new \Exception($th->getMessage()); } } /** * 微缩图函数 * @access public * @param $filepath * @param $filename * @param $config * @param bool $avatar * @param bool $newfile * @return Image|void * @throws \Exception */ public function thumb($filepath, $filename, $config, bool $avatar = false, bool $newfile = true) { $resource = $filepath . '/' . $filename; try { // 判断图片大小,原图尺寸不得小于微缩图 // 120x140 120x141 121x140 110x140 $ImageInfo = getimagesize($resource); if ($ImageInfo[0] >= $config['upload_thumb_w'] && $ImageInfo[1] >= $config['upload_thumb_h']) { $Image = Image::open($resource); // 判断微缩图类型 if (!empty($avatar)) { // 用户头像模式/替换原来的图片 $resThumb = $Image->thumb(110, 110, 6)->save($resource, NULL, 90); } else { if ($newfile) { // 保留原来的图片 新文件名建议源文件名+_thumb.jpg 格式 $resource = $filepath . '/thumb_' . $filename; } $resThumb = $Image->thumb($config['upload_thumb_w'], $config['upload_thumb_h'], 6)->save($resource, NULL, 90); } return $resThumb; } } catch (\Exception $e) { throw new \Exception($e->getMessage()); } } }