Skip to content

Commit b0f6563

Browse files
authored
feat() Use magick by default, fall back to convert if missing
This handles IM7 deprecation warnings and allows JPT to work on Windows, without breaking it on distros that ship IM6 such as ubuntu. * replaced convert with magick * Updated command? for Windows * Adding Fallback to convert ubuntu uses IM6 by default which doesn't support magick
1 parent b00aafd commit b0f6563

3 files changed

Lines changed: 26 additions & 5 deletions

File tree

docs/users/presets/image_formats.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,5 @@ used**. `original` does what you'd expect. To supply webp, you must have an
1717
imagemagick webp delegate installed. (Most package managers just name it 'webp')
1818

1919
_Supported formats are anything which imagemagick supports, and has an installed
20-
delegate. See a list by running `$ convert --version`_.
20+
delegate. See a list by running `$ magick --version`_.
2121

lib/jekyll_picture_tag/parsers/image_backend.rb

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,13 @@ def vips_formats
2828

2929
# Returns an array of formats that imagemagick can handle.
3030
def magick_formats
31-
if command?('convert')
31+
if command?('magick')
32+
@magick_formats ||= `magick -version`
33+
.scan(/Delegates.*/)
34+
.first
35+
.delete_prefix('Delegates (built-in):')
36+
.split
37+
elsif command?('convert')
3238
@magick_formats ||= `convert -version`
3339
.scan(/Delegates.*/)
3440
.first
@@ -56,7 +62,7 @@ def error_string(format)
5662
else
5763
'Libvips is not installed.'
5864
end
59-
str << if command?('convert')
65+
str << if command?('magick') || command?('convert')
6066
"Imagemagick (installed) supports: \"#{magick_formats.join(', ')}\"."
6167
else
6268
'Imagemagick is not installed.'
@@ -69,7 +75,12 @@ def alternates
6975
end
7076

7177
def command?(command)
72-
system("which #{command} > /dev/null 2>&1")
78+
is_windows = RbConfig::CONFIG['host_os'] =~ /mswin|mingw|cygwin/
79+
if is_windows
80+
system("where #{command} > NUL 2>&1")
81+
else
82+
system("which #{command} > /dev/null 2>&1")
83+
end
7384
end
7485
end
7586
end

test/test_helper.rb

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ def temp_dir(*descendents)
4949
# them doesn't support some image format. This returns an array of image
5050
# formats which we care about, and which are locally supported.
5151
def supported_formats
52-
output = `vips --list` + `convert --version`
52+
magick_command = command?('magick') ? `magick` : `convert`
53+
output = `vips --list` + `#{magick_command} --version`
5354

5455
formats = %w[jpg png webp gif jp2 avif].select do |format|
5556
output.include? format
@@ -60,4 +61,13 @@ def supported_formats
6061

6162
formats
6263
end
64+
65+
def command?(command)
66+
is_windows = RbConfig::CONFIG['host_os'] =~ /mswin|mingw|cygwin/
67+
if is_windows
68+
system("where #{command} > NUL 2>&1")
69+
else
70+
system("which #{command} > /dev/null 2>&1")
71+
end
72+
end
6373
end

0 commit comments

Comments
 (0)