From f7c01cccfb03e7e382c8a265aea31d93d968f839 Mon Sep 17 00:00:00 2001 From: Kijin Sung Date: Wed, 24 May 2023 14:28:26 +0900 Subject: [PATCH] Add options to convert AVIF and HEIC images using ImageMagick 7.x --- modules/file/file.admin.controller.php | 6 +++++- modules/file/file.admin.view.php | 3 ++- modules/file/file.model.php | 1 + modules/file/lang/en.php | 17 ++++++++++++----- modules/file/lang/ko.php | 17 ++++++++++++----- modules/file/tpl/upload_config.html | 26 ++++++++++++++++++++++++-- 6 files changed, 56 insertions(+), 14 deletions(-) diff --git a/modules/file/file.admin.controller.php b/modules/file/file.admin.controller.php index df7b68813..dbcf8e011 100644 --- a/modules/file/file.admin.controller.php +++ b/modules/file/file.admin.controller.php @@ -75,6 +75,8 @@ class FileAdminController extends File $config->image_autoconv['bmp2jpg'] = Context::get('image_autoconv_bmp2jpg') === 'Y' ? true : false; $config->image_autoconv['png2jpg'] = Context::get('image_autoconv_png2jpg') === 'Y' ? true : false; $config->image_autoconv['webp2jpg'] = Context::get('image_autoconv_webp2jpg') === 'Y' ? true : false; + $config->image_autoconv['avif2jpg'] = Context::get('image_autoconv_avif2jpg') === 'Y' ? true : false; + $config->image_autoconv['heic2jpg'] = Context::get('image_autoconv_heic2jpg') === 'Y' ? true : false; $config->image_autoconv['gif2mp4'] = Context::get('image_autoconv_gif2mp4') === 'Y' ? true : false; $config->max_image_width = intval(Context::get('max_image_width')) ?: ''; $config->max_image_height = intval(Context::get('max_image_height')) ?: ''; @@ -98,16 +100,18 @@ class FileAdminController extends File $config->video_thumbnail = Context::get('video_thumbnail') === 'Y' ? true : false; $config->video_mp4_gif_time = intval(Context::get('video_mp4_gif_time')); - // Path to ffmpeg and ffprobe + // Path to ffmpeg, ffprobe, magick if (RX_WINDOWS) { $config->ffmpeg_command = escape(Context::get('ffmpeg_command')) ?: 'C:\Program Files\ffmpeg\bin\ffmpeg.exe'; $config->ffprobe_command = escape(Context::get('ffprobe_command')) ?: 'C:\Program Files\ffmpeg\bin\ffprobe.exe'; + $config->magick_command = escape(Context::get('magick_command')) ?: ''; } else { $config->ffmpeg_command = escape(utf8_trim(Context::get('ffmpeg_command'))) ?: '/usr/bin/ffmpeg'; $config->ffprobe_command = escape(utf8_trim(Context::get('ffprobe_command'))) ?: '/usr/bin/ffprobe'; + $config->magick_command = escape(utf8_trim(Context::get('magick_command'))) ?: ''; } // Check maximum file size (probably not necessary anymore) diff --git a/modules/file/file.admin.view.php b/modules/file/file.admin.view.php index 8d133297f..6a5a4788a 100644 --- a/modules/file/file.admin.view.php +++ b/modules/file/file.admin.view.php @@ -222,7 +222,8 @@ class FileAdminView extends File $oFileModel = getModel('file'); $config = $oFileModel->getFileConfig(); Context::set('config', $config); - Context::set('is_ffmpeg', function_exists('exec') && Rhymix\Framework\Storage::isExecutable($config->ffmpeg_command) && Rhymix\Framework\Storage::isExecutable($config->ffprobe_command)); + Context::set('is_ffmpeg', function_exists('exec') && !empty($config->ffmpeg_command) && Rhymix\Framework\Storage::isExecutable($config->ffmpeg_command) && !empty($config->ffprobe_command) && Rhymix\Framework\Storage::isExecutable($config->ffprobe_command)); + Context::set('is_magick', function_exists('exec') && !empty($config->magick_command) && Rhymix\Framework\Storage::isExecutable($config->magick_command)); // Set a template file $this->setTemplatePath($this->module_path.'tpl'); diff --git a/modules/file/file.model.php b/modules/file/file.model.php index 2f1f95d00..124be2996 100644 --- a/modules/file/file.model.php +++ b/modules/file/file.model.php @@ -310,6 +310,7 @@ class FileModel extends File $config->video_mp4_gif_time = $config->video_mp4_gif_time ?? 0; $config->ffmpeg_command = $config->ffmpeg_command ?? '/usr/bin/ffmpeg'; $config->ffprobe_command = $config->ffprobe_command ?? '/usr/bin/ffprobe'; + $config->magick_command = $config->magick_command ?? ''; // Set allowed_extensions if(!isset($config->allowed_extensions)) diff --git a/modules/file/lang/en.php b/modules/file/lang/en.php index 10c1d078d..6f097fe50 100644 --- a/modules/file/lang/en.php +++ b/modules/file/lang/en.php @@ -86,10 +86,12 @@ $lang->about_use_image_default_file_config = 'Follow the default settings of ima $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 = 'convert the type of uploaded images. You can fix images that often cause trouble or waste disk space into other types.
This also works for WebP images that incorrectly have the JPG extension.'; +$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'; @@ -117,7 +119,12 @@ $lang->video_thumbnail = 'Video Thumbnail'; $lang->about_video_thumbnail = 'extract a thumbnail image from uploaded video.'; $lang->video_mp4_gif_time = 'Play Like GIF'; $lang->about_video_mp4_gif_time = 'treat silent MP4 videos with duration less than the set time as GIF images, and play with auto and loop.'; -$lang->ffmpeg_path = 'FFmpeg path'; -$lang->ffprobe_path = 'FFprobe path'; -$lang->msg_cannot_use_ffmpeg = 'FFmpeg and FFprobe must can be executed by PHP.'; -$lang->msg_cannot_use_exif = 'PHP Exif module is required.'; +$lang->external_program_paths = 'Paths to External Programs'; +$lang->ffmpeg_path = 'Absolute Path to ffmpeg'; +$lang->ffprobe_path = 'Absolute Path to ffprobe'; +$lang->magick_path = 'Absolute Path to magick'; +$lang->about_ffmpeg_path = 'Rhymix uses ffmpeg to convert video files.'; +$lang->about_magick_path = 'Rhymix uses magick to convert newer image formats such as AVIF and HEIC.
Note that the \'convert\' command from previous versions of ImageMagick doesn\'t support these formats.'; +$lang->msg_cannot_use_ffmpeg = 'In order to use this feature, PHP must be able to execute \'ffmpeg\' and \'ffprobe\' commands.'; +$lang->msg_cannot_use_exif = 'In order to use this feature, PHP must be installed with the \'exif\' extension.'; +$lang->msg_need_magick = 'In order to handle AVIF and HEIC formats, PHP must be able to execute the \'magick\' command from ImageMagick 7.x or higher.'; diff --git a/modules/file/lang/ko.php b/modules/file/lang/ko.php index adfe6385d..91414b8ce 100644 --- a/modules/file/lang/ko.php +++ b/modules/file/lang/ko.php @@ -87,10 +87,12 @@ $lang->about_use_image_default_file_config = '파일 모듈의 이미지 파일 $lang->use_video_default_file_config = '동영상 파일 기본 설정 사용'; $lang->about_use_video_default_file_config = '파일 모듈의 동영상 파일 기본 설정을 따릅니다.'; $lang->image_autoconv = '이미지 자동 변환'; -$lang->about_image_autoconv = '업로드된 이미지의 타입을 변환합니다. 종종 문제를 일으키거나 용량을 낭비하는 이미지를 해결할 수 있습니다.'; +$lang->about_image_autoconv = '업로드된 이미지의 타입을 변환합니다. 다양한 환경에서 호환되지 않거나, 용량을 낭비하는 이미지를 처리할 수 있습니다.'; $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 = '이미지 크기 제한'; $lang->about_max_image_size = '업로드된 이미지의 크기를 제한하거나 조정합니다. 파일 용량과는 직접적인 관계가 없으니 참고하세요.'; $lang->max_image_size_action_nothing = '초과시 아무 것도 하지 않음'; @@ -120,7 +122,12 @@ $lang->video_thumbnail = '동영상 섬네일 추출'; $lang->about_video_thumbnail = '업로드된 동영상에서 섬네일 이미지를 추출합니다.'; $lang->video_mp4_gif_time = 'GIF처럼 취급'; $lang->about_video_mp4_gif_time = '설정된 시간 이하의 길이를 가진 짧고 소리 없는 MP4 동영상은 GIF처럼 자동 재생 및 반복 재생 상태로 삽입합니다.'; -$lang->ffmpeg_path = 'FFmpeg 경로'; -$lang->ffprobe_path = 'FFprobe 경로'; -$lang->msg_cannot_use_ffmpeg = 'PHP에서 FFmpeg 및 FFprobe를 실행할 수 있어야 합니다.'; -$lang->msg_cannot_use_exif = 'PHP Exif 모듈이 필요합니다.'; +$lang->external_program_paths = '외부 프로그램 경로'; +$lang->ffmpeg_path = 'ffmpeg 절대경로'; +$lang->ffprobe_path = 'ffprobe 절대경로'; +$lang->magick_path = 'magick 절대경로'; +$lang->about_ffmpeg_path = '동영상 변환에 사용합니다.'; +$lang->about_magick_path = 'AVIF, HEIC 등 일부 이미지 변환에 사용합니다.
구 버전 ImageMagick의 convert 명령은 이러한 포맷을 지원하지 않습니다.'; +$lang->msg_cannot_use_ffmpeg = '이 기능을 사용하려면 PHP에서 ffmpeg 및 ffprobe 명령을 실행할 수 있어야 합니다.'; +$lang->msg_cannot_use_exif = '이 기능을 사용하려면 PHP exif 확장모듈이 필요합니다.'; +$lang->msg_need_magick = 'AVIF, HEIC 변환을 위해서는 PHP에서 ImageMagick 7.x 이상의 magick 명령을 실행할 수 있어야 합니다.'; diff --git a/modules/file/tpl/upload_config.html b/modules/file/tpl/upload_config.html index 316d32047..724094a40 100644 --- a/modules/file/tpl/upload_config.html +++ b/modules/file/tpl/upload_config.html @@ -47,7 +47,18 @@ {$lang->image_autoconv_webp2jpg} -

{$lang->about_image_autoconv}

+ + +

+ {$lang->about_image_autoconv}
+ {$lang->msg_need_magick} +

@@ -150,6 +161,7 @@

{$lang->about_max_video_size} +
{$lang->msg_cannot_use_ffmpeg}

{$lang->about_max_video_duration} +
{$lang->msg_cannot_use_ffmpeg}

-

FFmpeg

+

{lang('file.external_program_paths')}

+

{$lang->about_ffmpeg_path}

+

{$lang->about_ffmpeg_path}

+
+
+
+ +
+ +

{$lang->about_magick_path}