Module: JekyllAutoThumbnails::ImageMagickWrapper
- Defined in:
- lib/jekyll-auto-thumbnails/imagemagick_wrapper.rb
Overview
Wrapper for ImageMagick commands supporting both version 6 and 7
ImageMagick 6 uses convert and identify commands directly.
ImageMagick 7 uses magick convert and magick identify (or magick with subcommands).
This module detects the available version and provides a unified interface.
Class Method Summary collapse
-
.available? ⇒ Boolean
Check if ImageMagick is available (either version 6 or 7).
-
.convert_command ⇒ Array<String>
Get the convert command array for the detected ImageMagick version.
-
.detect_version ⇒ Symbol
Detect which ImageMagick version is available.
-
.execute_convert(*args) ⇒ Boolean
Execute convert command with arguments.
-
.execute_identify(*args) ⇒ Array<String, Process::Status>
Execute identify command with arguments.
-
.identify_command ⇒ Array<String>
Get the identify command array for the detected ImageMagick version.
-
.reset_detection_cache! ⇒ void
Clear the memoized result of ImageMagickWrapper.detect_version.
Class Method Details
.available? ⇒ Boolean
Check if ImageMagick is available (either version 6 or 7)
16 17 18 19 |
# File 'lib/jekyll-auto-thumbnails/imagemagick_wrapper.rb', line 16 def self.available? version = detect_version %i[v6 v7].include?(version) end |
.convert_command ⇒ Array<String>
Get the convert command array for the detected ImageMagick version
24 25 26 27 28 29 30 31 |
# File 'lib/jekyll-auto-thumbnails/imagemagick_wrapper.rb', line 24 def self.convert_command case detect_version when :v7 %w[magick convert] else ["convert"] # v6 and unavailable fallback (will fail if not available) end end |
.detect_version ⇒ Symbol
Detect which ImageMagick version is available
66 67 68 69 70 71 72 73 74 |
# File 'lib/jekyll-auto-thumbnails/imagemagick_wrapper.rb', line 66 def self.detect_version @detect_version ||= if command_exists?("magick") :v7 elsif command_exists?("convert") :v6 else :none end end |
.execute_convert(*args) ⇒ Boolean
Execute convert command with arguments
49 50 51 52 |
# File 'lib/jekyll-auto-thumbnails/imagemagick_wrapper.rb', line 49 def self.execute_convert(*args) cmd = convert_command + args system(*cmd) end |
.execute_identify(*args) ⇒ Array<String, Process::Status>
Execute identify command with arguments
58 59 60 61 |
# File 'lib/jekyll-auto-thumbnails/imagemagick_wrapper.rb', line 58 def self.execute_identify(*args) cmd = identify_command + args Open3.capture2e(*cmd) end |
.identify_command ⇒ Array<String>
Get the identify command array for the detected ImageMagick version
36 37 38 39 40 41 42 43 |
# File 'lib/jekyll-auto-thumbnails/imagemagick_wrapper.rb', line 36 def self.identify_command case detect_version when :v7 %w[magick identify] else ["identify"] # v6 and unavailable fallback (will fail if not available) end end |
.reset_detection_cache! ⇒ void
This method returns an undefined value.
Clear the memoized result of detect_version.
Intended for tests that mutate PATH between examples so detection can be re-probed through the public API rather than via reflection.
82 83 84 |
# File 'lib/jekyll-auto-thumbnails/imagemagick_wrapper.rb', line 82 def self.reset_detection_cache! @detect_version = nil end |