Class: MiniMagick::CommandBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/mini_magick/command_builder.rb

Constant Summary collapse

MOGRIFY_COMMANDS =
%w{adaptive-blur adaptive-resize adaptive-sharpen adjoin affine alpha annotate antialias append attenuate authenticate auto-gamma auto-level auto-orient backdrop background bench bias black-point-compensation black-threshold blend blue-primary blue-shift blur border bordercolor borderwidth brightness-contrast cache caption cdl channel charcoal chop clamp clip clip-mask clip-path clone clut coalesce colorize colormap color-matrix colors colorspace combine comment compose composite compress contrast contrast-stretch convolve crop cycle debug decipher deconstruct define delay delete density depth descend deskew despeckle direction displace display dispose dissimilarity-threshold dissolve distort dither draw duplicate edge emboss encipher encoding endian enhance equalize evaluate evaluate-sequence extent extract family features fft fill filter flatten flip floodfill flop font foreground format frame function fuzz fx gamma gaussian-blur geometry gravity green-primary hald-clut help highlight-color iconGeometry iconic identify ift immutable implode insert intent interlace interpolate interline-spacing interword-spacing kerning label lat layers level level-colors limit linear-stretch linewidth liquid-rescale list log loop lowlight-color magnify map mask mattecolor median metric mode modulate monitor monochrome morph morphology mosaic motion-blur name negate noise normalize opaque ordered-dither orient page paint path pause pen perceptible ping pointsize polaroid poly posterize precision preview print process profile quality quantize quiet radial-blur raise random-threshold red-primary regard-warnings region remap remote render repage resample resize respect-parentheses reverse roll rotate sample sampling-factor scale scene screen seed segment selective-blur separate sepia-tone set shade shadow shared-memory sharpen shave shear sigmoidal-contrast silent size sketch smush snaps solarize sparse-color splice spread statistic stegano stereo stretch strip stroke strokewidth style subimage-search swap swirl synchronize taint text-font texture threshold thumbnail tile tile-offset tint title transform transparent transparent-color transpose transverse treedepth trim type undercolor unique-colors units unsharp update verbose version view vignette virtual-pixel visual watermark wave weight white-point white-threshold window window-group write}
IMAGE_CREATION_OPERATORS =
%w{canvas caption gradient label logo pattern plasma radial radient rose text tile xc }

Instance Method Summary collapse

Constructor Details

#initialize(tool, *options) ⇒ CommandBuilder

Returns a new instance of CommandBuilder.



6
7
8
9
10
# File 'lib/mini_magick/command_builder.rb', line 6

def initialize(tool, *options)
  @tool = tool
  @args = []
  options.each { |arg| push(arg) }
end

Instance Method Details

#+(*options) ⇒ Object



71
72
73
74
75
76
77
78
# File 'lib/mini_magick/command_builder.rb', line 71

def +(*options)
  push(@args.pop.gsub(/^-/, '+'))
  if options.any?
    options.each do |o|
      push o
    end
  end
end

#add_command(command, *options) ⇒ Object



80
81
82
83
84
85
86
87
# File 'lib/mini_magick/command_builder.rb', line 80

def add_command(command, *options)
  push "-#{command}"
  if options.any?
    options.each do |o|
      push o
    end
  end
end

#add_creation_operator(command, *options) ⇒ Object



89
90
91
92
93
94
95
96
97
# File 'lib/mini_magick/command_builder.rb', line 89

def add_creation_operator(command, *options)
  creation_command = command
  if options.any?
    options.each do |option|
      creation_command << ":#{option}"
    end
  end
  push creation_command
end

#argsObject



31
32
33
34
35
36
37
# File 'lib/mini_magick/command_builder.rb', line 31

def args
  if !MiniMagick::Utilities.windows?
    @args.map(&:shellescape)
  else
    @args.map { |arg| escape_string_windows(arg) }
  end
end

#commandObject



12
13
14
15
16
17
18
# File 'lib/mini_magick/command_builder.rb', line 12

def command
  com = "#{@tool} #{args.join(' ')}".strip
  com = "#{MiniMagick.processor} #{com}" unless MiniMagick.mogrify?

  com = File.join MiniMagick.processor_path, com unless MiniMagick.processor_path.nil?
  com.strip
end

#escape_string_windows(value) ⇒ Object



20
21
22
23
24
25
26
27
28
29
# File 'lib/mini_magick/command_builder.rb', line 20

def escape_string_windows(value)
  # For Windows, ^ is the escape char, equivalent to \ in Unix.
  escaped = value.gsub(/\^/, '^^').gsub(/>/, '^>')
  if escaped !~ /^".+"$/ && escaped.include?("'")
    escaped.inspect
  else
    escaped
  end

end

#format(*options) ⇒ Object

Raises:



60
61
62
# File 'lib/mini_magick/command_builder.rb', line 60

def format(*options)
  raise Error, "You must call 'format' on the image object directly!"
end

#push(arg) ⇒ Object Also known as: <<



99
100
101
# File 'lib/mini_magick/command_builder.rb', line 99

def push(arg)
  @args << arg.to_s.strip
end