Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/users/presets/image_formats.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`_.

17 changes: 14 additions & 3 deletions lib/jekyll_picture_tag/parsers/image_backend.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.'
Expand All @@ -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
Expand Down
12 changes: 11 additions & 1 deletion test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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