Add option to convert to WebP when resizing oversized images

This commit is contained in:
Kijin Sung 2024-12-16 20:47:48 +09:00
parent 9f75788491
commit d27f89f730
5 changed files with 14 additions and 13 deletions

View file

@ -87,7 +87,7 @@ class FileAdminController extends File
$config->max_image_width = intval(Context::get('max_image_width')) ?: '';
$config->max_image_height = intval(Context::get('max_image_height')) ?: '';
$config->max_image_size_action = Context::get('max_image_size_action') ?: '';
$config->max_image_size_same_format = Context::get('max_image_size_same_format') === 'Y' ? 'Y' : 'N';
$config->max_image_size_same_format = strval(Context::get('max_image_size_same_format'));
$config->max_image_size_admin = Context::get('max_image_size_admin') === 'Y' ? 'Y' : 'N';
$config->image_quality_adjustment = max(50, min(100, intval(Context::get('image_quality_adjustment'))));
$config->image_autorotate = Context::get('image_autorotate') === 'Y' ? true : false;

View file

@ -1247,7 +1247,7 @@ class FileController extends File
$adjusted['height'] = (int)$resize_height;
if (!$is_animated && $adjusted['type'] === $image_info['type'] && $config->max_image_size_same_format !== 'Y')
{
$adjusted['type'] = 'jpg';
$adjusted['type'] = $config->max_image_size_same_format ?: 'jpg';
}
}
}

View file

@ -90,11 +90,6 @@ $lang->use_video_default_file_config = 'Use Default Settings Of Video File';
$lang->about_use_video_default_file_config = 'Follow the video settings of image file from the File module.';
$lang->image_autoconv = 'Convert Type';
$lang->about_image_autoconv = 'Automatically convert uploaded images. This may help you handle image formats that are not widely supported or waste disk space.';
$lang->image_autoconv_bmp2jpg = 'BMP → JPG';
$lang->image_autoconv_png2jpg = 'PNG → JPG';
$lang->image_autoconv_webp2jpg = 'WebP → JPG';
$lang->image_autoconv_avif2jpg = 'AVIF → JPG';
$lang->image_autoconv_heic2jpg = 'HEIC → JPG';
$lang->max_image_size = 'Limit Image Size';
$lang->about_max_image_size = 'Limit the dimensions of uploaded images. Note that this is only indirectly related to file size.';
$lang->max_image_size_action_nothing = 'If exceeded, do nothing';
@ -102,7 +97,8 @@ $lang->max_image_size_action_block = 'If exceeded, block upload';
$lang->max_image_size_action_resize = 'If exceeded, resize automatically';
$lang->max_image_size_action_cut = 'If exceeded, cut automatically';
$lang->max_image_size_same_format_Y = 'Maintain file format';
$lang->max_image_size_same_format_N = 'Convert to JPG';
$lang->max_image_size_same_format_to_jpg = 'Convert to JPG';
$lang->max_image_size_same_format_to_webp = 'Convert to WebP';
$lang->max_image_size_admin = 'Also apply to administrator';
$lang->image_quality_adjustment = 'Image Quality';
$lang->about_image_quality_adjustment = 'adjust the quality of images that will is converted by other settings.<br />If set to more than 75% (Standard), the file size may be larger than the original.';

View file

@ -98,7 +98,8 @@ $lang->max_image_size_action_block = '초과시 업로드 금지';
$lang->max_image_size_action_resize = '초과시 자동 크기 조정';
$lang->max_image_size_action_cut = '초과시 자르기';
$lang->max_image_size_same_format_Y = '동일한 포맷 유지';
$lang->max_image_size_same_format_N = 'JPG로 변환';
$lang->max_image_size_same_format_to_jpg = 'JPG로 변환';
$lang->max_image_size_same_format_to_webp = 'WebP로 변환';
$lang->max_image_size_admin = '관리자에게도 적용';
$lang->image_quality_adjustment = '이미지 화질';
$lang->about_image_quality_adjustment = '다른 설정에 의해 이미지가 변환될 경우 화질을 조정합니다.<br />75% (표준) 이상으로 설정시 오히려 원본보다 용량이 늘어날 수 있습니다.';

View file

@ -70,12 +70,16 @@
</p>
<p class="x_help-block">
<label class="x_inline" for="max_image_size_same_format_Y">
<input type="radio" name="max_image_size_same_format" id="max_image_size_same_format_Y" value="Y" checked="checked"|cond="$config->max_image_size_same_format === 'Y'" />
<input type="radio" name="max_image_size_same_format" id="max_image_size_same_format_Y" value="Y" checked="checked"|cond="!isset($config->max_image_size_same_format) || $config->max_image_size_same_format === 'Y'" />
{$lang->max_image_size_same_format_Y}
</label>
<label class="x_inline" for="max_image_size_same_format_N">
<input type="radio" name="max_image_size_same_format" id="max_image_size_same_format_N" value="N" checked="checked"|cond="$config->max_image_size_same_format !== 'Y'" />
{$lang->max_image_size_same_format_N}
<label class="x_inline" for="max_image_size_same_format_to_jpg">
<input type="radio" name="max_image_size_same_format" id="max_image_size_same_format_to_jpg" value="jpg" checked="checked"|cond="$config->max_image_size_same_format === 'jpg' || $config->max_image_size_same_format === 'N'" />
{$lang->max_image_size_same_format_to_jpg}
</label>
<label class="x_inline" for="max_image_size_same_format_to_webp">
<input type="radio" name="max_image_size_same_format" id="max_image_size_same_format_to_webp" value="webp" checked="checked"|cond="$config->max_image_size_same_format === 'webp'" />
{$lang->max_image_size_same_format_to_webp}
</label>
<label for="max_image_size_admin">
<input type="checkbox" name="max_image_size_admin" id="max_image_size_admin" value="Y" checked="checked"|cond="$config->max_image_size_admin === 'Y'" />