Class: JekyllImgFlow::Providers::Imagemagick

Inherits:
CliBase show all
Defined in:
lib/jekyll-imgflow/providers/imagemagick.rb

Overview

ImageMagick provider implementation using the standardized tag interface

Constant Summary

Constants inherited from BaseProvider

BaseProvider::COMPASS_TO_SHORT, BaseProvider::KNOWN_OPERATIONS, BaseProvider::SMARTCROP_POSITIONS

Instance Attribute Summary

Attributes inherited from BaseProvider

#config

Instance Method Summary collapse

Methods inherited from CliBase

#execute

Methods inherited from BaseProvider

#add_watermark, #alpha_byte_value, #alpha_opacity=, #check_http_service, #cli_available?, #compass_to_short, #convert_format, #crop, #crop_coords, #crop_geometry, #encode_file_url, #execute, #find_op, #format, #initialize, #input_format_ext, #op?, #opacity, #operations, #optimize, provider_name, #quality, #quality=, #relative_file_path, #reset_operations, #resize, #smartcrop_interestingness, #supports_operation?, supports_operation?, #temp_path, unsupported_operations, #watermark, #watermark_parts

Constructor Details

This class inherits a constructor from JekyllImgFlow::Providers::BaseProvider

Instance Method Details

#available? ⇒ Boolean

Returns:

  • (Boolean)


15
16
17
# File 'lib/jekyll-imgflow/providers/imagemagick.rb', line 15

def available?
  cli_available?("magick", "convert")
end

#before_execute(input_path) ⇒ Object



19
20
21
22
# File 'lib/jekyll-imgflow/providers/imagemagick.rb', line 19

def before_execute(input_path)
  # Warn once per build about SVG performance with ImageMagick
  warn_svg_performance if svg?(input_path) && !self.class.instance_variable_get(:@svg_warning_shown)
end

#build_combined_imagemagick_command(input_path, output_path) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/jekyll-imgflow/providers/imagemagick.rb', line 28

def build_combined_imagemagick_command(input_path, output_path)
  # Start with base command.
  # For SVGs, set -density before the input so ImageMagick rasterizes
  # at a reasonable resolution instead of the full viewBox (which can
  # be 10000x8500 = 85M pixels, making each conversion take 10+ seconds).
  # With the rsvg delegate installed, -density controls the render DPI.
  # Without rsvg, ImageMagick uses its slow internal MSVG parser.
  command_parts = if svg?(input_path)
                    ["magick", "-density", svg_density.to_s, input_path.shellescape]
                  else
                    ["magick", input_path.shellescape]
                  end

  @operations.each { |operation| append_imagemagick_operation(operation, command_parts) }

  # Add output filename
  command_parts << output_path.shellescape

  command_parts.join(" ")
end

#build_commands(input_path, output_path) ⇒ Object



24
25
26
# File 'lib/jekyll-imgflow/providers/imagemagick.rb', line 24

def build_commands(input_path, output_path)
  build_combined_imagemagick_command(input_path, output_path)
end

#translate_position(position) ⇒ Object



49
50
51
52
53
54
55
56
57
58
# File 'lib/jekyll-imgflow/providers/imagemagick.rb', line 49

def translate_position(position)
  case position
  when "northwest" then "NorthWest"
  when "northeast" then "NorthEast"
  when "southwest" then "SouthWest"
  when "southeast" then "SouthEast"
  when "center" then "Center"
  else position
  end
end