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

Class Method Details

.available?Boolean

Check if ImageMagick is available (either version 6 or 7)

Returns:

  • (Boolean)

    true if ImageMagick is available



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_commandArray<String>

Get the convert command array for the detected ImageMagick version

Returns:

  • (Array<String>)

    command array (e.g., ["convert"] or ["magick", "convert"])



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_versionSymbol

Detect which ImageMagick version is available

Returns:

  • (Symbol)

    :v6, :v7, or :none



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

Parameters:

  • args (Array<String>)

    arguments to pass to convert

Returns:

  • (Boolean)

    true if command succeeded



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

Parameters:

  • args (Array<String>)

    arguments to pass to identify

Returns:

  • (Array<String, Process::Status>)

    [output, status] tuple



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_commandArray<String>

Get the identify command array for the detected ImageMagick version

Returns:

  • (Array<String>)

    command array (e.g., ["identify"] or ["magick", "identify"])



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