Add options to convert AVIF and HEIC images using ImageMagick 7.x

This commit is contained in:
Kijin Sung 2023-05-24 14:28:26 +09:00
parent 51a4604750
commit f7c01cccfb
6 changed files with 56 additions and 14 deletions

View file

@ -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)

View file

@ -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');

View file

@ -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))

View file

@ -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.<br />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.<br />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.';

View file

@ -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 등 일부 이미지 변환에 사용합니다.<br />구 버전 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 명령을 실행할 수 있어야 합니다.';

View file

@ -47,7 +47,18 @@
<input type="checkbox" name="image_autoconv_webp2jpg" id="image_autoconv_webp2jpg" value="Y" checked="checked"|cond="$config->image_autoconv['webp2jpg']" disabled="disabled"|cond="!function_exists('imagewebp')" />
{$lang->image_autoconv_webp2jpg}
</label>
<p class="x_help-block">{$lang->about_image_autoconv}</p>
<label for="image_autoconv_avif2jpg">
<input type="checkbox" name="image_autoconv_avif2jpg" id="image_autoconv_avif2jpg" value="Y" checked="checked"|cond="$config->image_autoconv['avif2jpg']" disabled="disabled"|cond="!$is_magick" />
{$lang->image_autoconv_avif2jpg}
</label>
<label for="image_autoconv_heic2jpg">
<input type="checkbox" name="image_autoconv_heic2jpg" id="image_autoconv_heic2jpg" value="Y" checked="checked"|cond="$config->image_autoconv['heic2jpg']" disabled="disabled"|cond="!$is_magick" />
{$lang->image_autoconv_heic2jpg}
</label>
<p class="x_help-block">
{$lang->about_image_autoconv}<br />
{$lang->msg_need_magick}
</p>
</div>
</div>
<div class="x_control-group">
@ -150,6 +161,7 @@
</select>
<p class="x_help-block">
{$lang->about_max_video_size}
<span class="x_text-info" cond="!$is_ffmpeg"><br />{$lang->msg_cannot_use_ffmpeg}</span>
</p>
<p>
<label for="max_video_size_admin">
@ -170,6 +182,7 @@
</select>
<p class="x_help-block">
{$lang->about_max_video_duration}
<span class="x_text-info" cond="!$is_ffmpeg"><br />{$lang->msg_cannot_use_ffmpeg}</span>
</p>
<p>
<label for="max_video_duration_admin">
@ -234,17 +247,26 @@
</div>
</section>
<section class="section">
<h1>FFmpeg</h1>
<h1>{lang('file.external_program_paths')}</h1>
<div class="x_control-group">
<label class="x_control-label">{$lang->ffmpeg_path}</label>
<div class="x_controls">
<input type="text" name="ffmpeg_command" value="{$config->ffmpeg_command}" />
<p class="x_help-block">{$lang->about_ffmpeg_path}</p>
</div>
</div>
<div class="x_control-group">
<label class="x_control-label">{$lang->ffprobe_path}</label>
<div class="x_controls">
<input type="text" name="ffprobe_command" value="{$config->ffprobe_command}" />
<p class="x_help-block">{$lang->about_ffmpeg_path}</p>
</div>
</div>
<div class="x_control-group">
<label class="x_control-label">{$lang->magick_path}</label>
<div class="x_controls">
<input type="text" name="magick_command" value="{$config->magick_command}" />
<p class="x_help-block">{$lang->about_magick_path}</p>
</div>
</div>
</section>