diff --git a/docs/users/presets/image_formats.md b/docs/users/presets/image_formats.md index 58159742..e961e498 100644 --- a/docs/users/presets/image_formats.md +++ b/docs/users/presets/image_formats.md @@ -17,5 +17,5 @@ used**. `original` does what you'd expect. To supply webp, you must have an imagemagick webp delegate installed. (Most package managers just name it 'webp') _Supported formats are anything which imagemagick supports, and has an installed -delegate. See a list by running `$ convert --version`_. +delegate. See a list by running `$ magick --version`_. diff --git a/lib/jekyll_picture_tag/parsers/image_backend.rb b/lib/jekyll_picture_tag/parsers/image_backend.rb index 2593da2f..38de4deb 100644 --- a/lib/jekyll_picture_tag/parsers/image_backend.rb +++ b/lib/jekyll_picture_tag/parsers/image_backend.rb @@ -28,7 +28,13 @@ def vips_formats # Returns an array of formats that imagemagick can handle. def magick_formats - if command?('convert') + if command?('magick') + @magick_formats ||= `magick -version` + .scan(/Delegates.*/) + .first + .delete_prefix('Delegates (built-in):') + .split + elsif command?('convert') @magick_formats ||= `convert -version` .scan(/Delegates.*/) .first @@ -56,7 +62,7 @@ def error_string(format) else 'Libvips is not installed.' end - str << if command?('convert') + str << if command?('magick') || command?('convert') "Imagemagick (installed) supports: \"#{magick_formats.join(', ')}\"." else 'Imagemagick is not installed.' @@ -69,7 +75,12 @@ def alternates end def command?(command) - system("which #{command} > /dev/null 2>&1") + is_windows = RbConfig::CONFIG['host_os'] =~ /mswin|mingw|cygwin/ + if is_windows + system("where #{command} > NUL 2>&1") + else + system("which #{command} > /dev/null 2>&1") + end end end end diff --git a/test/test_helper.rb b/test/test_helper.rb index 18eaf56c..8a6f1224 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -49,7 +49,8 @@ def temp_dir(*descendents) # them doesn't support some image format. This returns an array of image # formats which we care about, and which are locally supported. def supported_formats - output = `vips --list` + `convert --version` + magick_command = command?('magick') ? `magick` : `convert` + output = `vips --list` + `#{magick_command} --version` formats = %w[jpg png webp gif jp2 avif].select do |format| output.include? format @@ -60,4 +61,13 @@ def supported_formats formats end + + def command?(command) + is_windows = RbConfig::CONFIG['host_os'] =~ /mswin|mingw|cygwin/ + if is_windows + system("where #{command} > NUL 2>&1") + else + system("which #{command} > /dev/null 2>&1") + end + end end