Browse files

Merge pull request #51 from mikehoward/add-image-operators

added support for internal image creation operators
  • Loading branch information...
2 parents 5838f40 + 63d701e commit 363c74d1db5a935e3c22e86270a328586b4e6104 @hcatlin hcatlin committed Oct 12, 2011
Showing with 31 additions and 2 deletions.
  1. +1 −0 .gitignore
  2. +7 −0 README.rdoc
  3. +17 −2 lib/mini_magick.rb
  4. +6 −0 test/command_builder_test.rb
1 .gitignore
@@ -1,3 +1,4 @@
7 README.rdoc
@@ -83,6 +83,13 @@ Want to get some meta-information out?
image["EXIF:BitsPerSample"] # It also can get all the EXIF tags
image["%m:%f %wx%h"] # Or you can use one of the many options of the format command
+Want to use an internal image creation to create a big black square?
+ image = MiniMagick::Image.create 'jpg', false do |c|
+ c.size '1024x1024' # creates image option '-size 1024x1024'
+ c.canvas 'black' # creates image creation operator 'canvas:black'
+ end
For more on the format command see
19 lib/mini_magick.rb
@@ -24,6 +24,8 @@ def choose_processor
MOGRIFY_COMMANDS = %w{adaptive-blur adaptive-resize adaptive-sharpen adjoin affine alpha annotate antialias append authenticate auto-gamma auto-level auto-orient background bench iterations bias black-threshold blue-primary point blue-shift factor blur border bordercolor brightness-contrast caption string cdl filename channel type charcoal radius chop clip clamp clip-mask filename clip-path id clone index clut contrast-stretch coalesce colorize color-matrix colors colorspace type combine comment string compose operator composite compress type contrast convolve coefficients crop cycle amount decipher filename debug events define format:option deconstruct delay delete index density depth despeckle direction type display server dispose method distort type coefficients dither method draw string edge radius emboss radius encipher filename encoding type endian type enhance equalize evaluate operator evaluate-sequence operator extent extract family name fft fill filter type flatten flip floodfill flop font name format string frame function name fuzz distance fx expression gamma gaussian-blur geometry gravity type green-primary point help identify ifft implode amount insert index intent type interlace type interline-spacing interpolate method interword-spacing kerning label string lat layers method level limit type linear-stretch liquid-rescale log format loop iterations mask filename mattecolor median radius modulate monitor monochrome morph morphology method kernel motion-blur negate noise radius normalize opaque ordered-dither NxN orient type page paint radius ping pointsize polaroid angle posterize levels precision preview type print string process image-filter profile filename quality quantize quiet radial-blur angle raise random-threshold low,high red-primary point regard-warnings region remap filename render repage resample resize respect-parentheses roll rotate degrees sample sampling-factor scale scene seed segments selective-blur separate sepia-tone threshold set attribute shade degrees shadow sharpen shave shear sigmoidal-contrast size sketch solarize threshold splice spread radius strip stroke strokewidth stretch type style type swap indexes swirl degrees texture filename threshold thumbnail tile filename tile-offset tint transform transparent transparent-color transpose transverse treedepth trim type type undercolor unique-colors units type unsharp verbose version view vignette virtual-pixel method wave weight type white-point point white-threshold write filename}
+ IMAGE_CREATION_OPERATORS = %w{canvas caption gradient label logo pattern plasma radial radient rose text tile xc }
class Error < RuntimeError; end
class Invalid < StandardError; end
@@ -436,7 +438,10 @@ def method_missing(symbol, *options)
if guessed_command_name == "format"
raise Error, "You must call 'format' on the image object directly!"
elsif MOGRIFY_COMMANDS.include?(guessed_command_name)
- add(guessed_command_name, *options)
+ add_command(guessed_command_name, *options)
+ self
+ elsif IMAGE_CREATION_OPERATORS.include?(guessed_command_name)
+ add_creation_operator(guessed_command_name, *options)
super(symbol, *args)
@@ -452,7 +457,7 @@ def +(*options)
- def add(command, *options)
+ def add_command(command, *options)
push "-#{command}"
if options.any?
options.each do |o|
@@ -461,6 +466,16 @@ def add(command, *options)
+ 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
def push(arg)
@args << arg.to_s.strip
6 test/command_builder_test.rb
@@ -40,4 +40,10 @@ def test_dashed
assert_equal "-auto-orient", c.args.join(" ")
+ def test_canvas
+ c ='test')
+ c.canvas 'black'
+ assert_equal "canvas:black", c.args.join
+ end

0 comments on commit 363c74d

Please sign in to comment.