fix: 水印处理
This commit is contained in:
@@ -42,7 +42,7 @@ class Upload
|
|||||||
$filemd5 = $file->md5();
|
$filemd5 = $file->md5();
|
||||||
$filesha1 = $file->sha1();
|
$filesha1 = $file->sha1();
|
||||||
|
|
||||||
$image_model = SysImageUploadRecordModel::md5($filemd5)->find();
|
$image_model = null; // SysImageUploadRecordModel::md5($filemd5)->find();
|
||||||
if (is_null($image_model)) {
|
if (is_null($image_model)) {
|
||||||
$filename = Filesystem::disk('image')->putFile($param['module'], $file);
|
$filename = Filesystem::disk('image')->putFile($param['module'], $file);
|
||||||
// 处理图片
|
// 处理图片
|
||||||
@@ -50,14 +50,19 @@ class Upload
|
|||||||
$image = $image_manager->read('.' . $storage . '/' . $filename);
|
$image = $image_manager->read('.' . $storage . '/' . $filename);
|
||||||
|
|
||||||
// 水印
|
// 水印
|
||||||
list($enabled, $type, $text_options, $image_options) = $this->getWatermarkOptions();
|
list(
|
||||||
|
'enabled' => $enabled,
|
||||||
|
'type' => $type,
|
||||||
|
'text_options' => $text_options,
|
||||||
|
'image_options' => $image_options
|
||||||
|
) = $this->getWatermarkOptions();
|
||||||
if ($enabled) {
|
if ($enabled) {
|
||||||
// 图片水印
|
// 图片水印
|
||||||
if ($type == 'IMAGE' && $image_options['image'] != '') {
|
if ($type == 'IMAGE' && $image_options['image'] != '') {
|
||||||
// 读取水印图片
|
// 读取水印图片
|
||||||
$watermark_image = $image_manager->read($image_options['image']);
|
$watermark_image = $image_manager->read(public_path() . $image_options['image']);
|
||||||
// 缩放水印图片
|
// 缩放水印图片
|
||||||
$watermark_image->scale($image_options['width'], $image_options['height']);
|
$watermark_image->scale((int)$image_options['width'], (int)$image_options['height']);
|
||||||
// 绘制水印图片
|
// 绘制水印图片
|
||||||
$image->place(
|
$image->place(
|
||||||
$watermark_image,
|
$watermark_image,
|
||||||
@@ -76,12 +81,14 @@ class Upload
|
|||||||
|
|
||||||
$font_factory = new FontFactory(function(FontFactory $font) use($text_options) {
|
$font_factory = new FontFactory(function(FontFactory $font) use($text_options) {
|
||||||
// 设置字体
|
// 设置字体
|
||||||
$font->filename($text_options['font']);
|
$font->filename(public_path() . $text_options['font']);
|
||||||
// 设置字体大小
|
// 设置字体大小
|
||||||
$font->size($text_options['size']);
|
$font->size($text_options['size']);
|
||||||
// 设置字体颜色及透明度
|
// 设置字体颜色及透明度
|
||||||
$opacity = dechex((int)ceil(255 * ($text_options['opacity'] / 100)));
|
$opacity = dechex((int)ceil(255 * ($text_options['opacity'] / 100)));
|
||||||
$font->color($text_options['color'] . $opacity);
|
$font->color($text_options['color'] . $opacity);
|
||||||
|
$font->align('left');
|
||||||
|
$font->valign('top');
|
||||||
});
|
});
|
||||||
// 文字尺寸
|
// 文字尺寸
|
||||||
$font_rect = $image->driver()->fontProcessor()->boxSize($text_options['txt'], $font_factory());
|
$font_rect = $image->driver()->fontProcessor()->boxSize($text_options['txt'], $font_factory());
|
||||||
@@ -149,11 +156,11 @@ class Upload
|
|||||||
$config_model = new \app\admin\controller\v1\SiteConfig;
|
$config_model = new \app\admin\controller\v1\SiteConfig;
|
||||||
$watermark_config = $config_model->getByGroupUniqueLabel('watermark');
|
$watermark_config = $config_model->getByGroupUniqueLabel('watermark');
|
||||||
return [
|
return [
|
||||||
'enalbed' => data_get($watermark_config, 'watermark_enabled.value', 0) == 1,
|
'enabled' => data_get($watermark_config, 'watermark_enabled.value', 0) == 1,
|
||||||
'type' => data_get($watermark_config, 'watermark_type.value', ''),
|
'type' => data_get($watermark_config, 'watermark_type.value', ''),
|
||||||
'text_options' => [
|
'text_options' => [
|
||||||
'txt' => data_get($watermark_config, 'watermark_text_value.value', ''),
|
'txt' => data_get($watermark_config, 'watermark_text_value.value', ''),
|
||||||
'font' => data_get($watermark_config, 'watermark_font_family.value', ''),
|
'font' => data_get($watermark_config, 'watermark_text_font.value', ''),
|
||||||
'size' => (float)data_get($watermark_config, 'watermark_text_size.value', 12),
|
'size' => (float)data_get($watermark_config, 'watermark_text_size.value', 12),
|
||||||
'color' => data_get($watermark_config, 'watermark_text_color.value', '#000000'),
|
'color' => data_get($watermark_config, 'watermark_text_color.value', '#000000'),
|
||||||
'position' => data_get($watermark_config, 'watermark_position.value', 'top-left'),
|
'position' => data_get($watermark_config, 'watermark_position.value', 'top-left'),
|
||||||
@@ -169,7 +176,7 @@ class Upload
|
|||||||
'offset_x' => (int)data_get($watermark_config, 'watermark_offset_x.value', 0),
|
'offset_x' => (int)data_get($watermark_config, 'watermark_offset_x.value', 0),
|
||||||
'offset_y' => (int)data_get($watermark_config, 'watermark_offset_y.value', 0),
|
'offset_y' => (int)data_get($watermark_config, 'watermark_offset_y.value', 0),
|
||||||
'opacity' => (int)data_get($watermark_config, 'watermark_opacity.value', 100),
|
'opacity' => (int)data_get($watermark_config, 'watermark_opacity.value', 100),
|
||||||
],
|
]
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user