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).
-
.command_exists?(cmd) ⇒ Boolean
Check if a command exists in PATH.
-
.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.
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 |
.command_exists?(cmd) ⇒ Boolean
Check if a command exists in PATH
86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/jekyll-auto-thumbnails/imagemagick_wrapper.rb', line 86 def self.command_exists?(cmd) cmd_name = Gem.win_platform? ? "#{cmd}.exe" : cmd path_dirs = ENV["PATH"].to_s.split(File::PATH_SEPARATOR) path_dirs.any? do |dir| # Use File.join for cross-platform path construction # On Unix, this will use forward slashes even for Windows-style paths in tests executable = File.join(dir, cmd_name) File.executable?(executable) end end |
.convert_command ⇒ Array<String>
Get the convert command array for the detected ImageMagick version
24 25 26 27 28 29 30 31 32 33 |
# File 'lib/jekyll-auto-thumbnails/imagemagick_wrapper.rb', line 24 def self.convert_command case detect_version when :v7 %w[magick convert] when :v6 ["convert"] else ["convert"] # Default fallback (will fail if not available) end end |
.detect_version ⇒ Symbol
Detect which ImageMagick version is available
70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/jekyll-auto-thumbnails/imagemagick_wrapper.rb', line 70 def self.detect_version return @detected_version if defined?(@detected_version) && @detected_version @detected_version = if command_exists?("magick") :v7 elsif command_exists?("convert") :v6 else :none end end |
.execute_convert(*args) ⇒ Boolean
Execute convert command with arguments
53 54 55 56 |
# File 'lib/jekyll-auto-thumbnails/imagemagick_wrapper.rb', line 53 def self.execute_convert(*args) cmd = convert_command + args system(*cmd) end |
.execute_identify(*args) ⇒ Array<String, Process::Status>
Execute identify command with arguments
62 63 64 65 |
# File 'lib/jekyll-auto-thumbnails/imagemagick_wrapper.rb', line 62 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
38 39 40 41 42 43 44 45 46 47 |
# File 'lib/jekyll-auto-thumbnails/imagemagick_wrapper.rb', line 38 def self.identify_command case detect_version when :v7 %w[magick identify] when :v6 ["identify"] else ["identify"] # Default fallback (will fail if not available) end end |