Class: Fleximage::Operator::Border

Inherits:
Base
  • Object
show all
Defined in:
lib/fleximage/operator/border.rb

Overview

Add a border to the outside of the image

image.border(options = {})

Use the following keys in the options hash:

  • size: Width of the border on each side. You can use a 2 dimensional value (‘5x10’) if you want different widths for the sides and top borders, but a single integer will apply the same border on all sides.

  • color: the color of the border. Use an RMagick named color or use the color method in FlexImage::Controller, or a Magick::Pixel object.

Example:

@photo.operate do |image|
  # Defaults
  image.border(
    :size  => 10,
    :color => 'white'    # or color(255, 255, 255)
  )

  # Big, pink and wide
  image.border(
    :size  => '200x100',
    :color => color(255, 128, 128)
  )
end

Instance Method Summary collapse

Methods inherited from Base

#color, color, #execute, #initialize, #scale, #scale_and_crop, size_to_xy, #size_to_xy, #stretch, #symbol_to_blending_mode, #symbol_to_gravity

Constructor Details

This class inherits a constructor from Fleximage::Operator::Base

Instance Method Details

#operate(options = {}) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/fleximage/operator/border.rb', line 33

def operate(options = {})
  options = options.symbolize_keys if options.respond_to?(:symbolize_keys)
  defaults = {
    :size => '10',
    :color => 'white'
  }
  options = options.is_a?(Hash) ? defaults.update(options) : defaults
  
  # Get border size
  options[:size] = size_to_xy(options[:size])

  # apply border
  @image.border!(options[:size][0], options[:size][1], options[:color])
end