class ImageParadise::SimpleLabel

Constants

DEFAULT_FONT_TO_USE
#

DEFAULT_FONT_TO_USE

#
DEFAULT_IMAGE_FORMAT
#

DEFAULT_IMAGE_FORMAT

#
DO_OPEN_IN_BROWSER
#

DO_OPEN_IN_BROWSER

#
REGEX_FOR_SIZE
#

REGEX_FOR_SIZE

#

Public Class Methods

new( i = ARGV, run_already = true ) click to toggle source
#

initialize

#
# File lib/image_paradise/label/simple_label.rb, line 42
def initialize(
    i           = ARGV,
    run_already = true
  )
  reset
  set_label(i)
  run if run_already
end

Public Instance Methods

add_default_background() click to toggle source
#

add_default_background

#
# File lib/image_paradise/label/simple_label.rb, line 119
def add_default_background
  @_ << ' -background '+@background
end
add_default_fill() click to toggle source
#

add_default_fill

#
# File lib/image_paradise/label/simple_label.rb, line 179
def add_default_fill
  @_ << ' -fill '+@fill
end
add_default_font() click to toggle source
#

add_default_font

#
# File lib/image_paradise/label/simple_label.rb, line 126
def add_default_font
  @_ << ' -font '+@font
end
add_default_gravity() click to toggle source
#

add_default_gravity

#
# File lib/image_paradise/label/simple_label.rb, line 144
def add_default_gravity
  @_ << ' -gravity center'
end
add_default_pointsize() click to toggle source
#

add_default_pointsize

#
# File lib/image_paradise/label/simple_label.rb, line 172
def add_default_pointsize
  @_ << ' -pointsize '+@pointsize
end
add_label() click to toggle source
#

add_label

#
# File lib/image_paradise/label/simple_label.rb, line 133
def add_label
  _ = @label
  if _.include? ' '
    _ = '"'+_+'"'
  end
  @_ << ' label:'+_
end
add_output_file() click to toggle source
#

add_output_file

#
# File lib/image_paradise/label/simple_label.rb, line 158
def add_output_file
  @_ << ' '+@output_file
end
add_size() click to toggle source
#

add_size

#
# File lib/image_paradise/label/simple_label.rb, line 112
def add_size
  @_ << ' -size '+@size
end
build_up_main_command() click to toggle source
#

build_up_main_command

#
# File lib/image_paradise/label/simple_label.rb, line 97
def build_up_main_command
  @_ = 'convert'.dup
  add_default_background
  add_default_fill
  add_default_font
  add_default_gravity
  add_size
  add_label
  # add_default_pointsize # Do not add this option if you also added the default size.
  add_output_file
end
consider_opening_in_the_browser() click to toggle source
#

consider_opening_in_the_browser

#
# File lib/image_paradise/label/simple_label.rb, line 186
def consider_opening_in_the_browser
  if DO_OPEN_IN_BROWSER
    Open.in_browser(output_file?)
  end
end
output_file?() click to toggle source
#

output_file?

#
# File lib/image_paradise/label/simple_label.rb, line 165
def output_file?
  @output_file
end
output_then_run_the_main_command() click to toggle source
#

output_then_run_the_main_command

#
# File lib/image_paradise/label/simple_label.rb, line 151
def output_then_run_the_main_command
  esystem @_
end
reset() click to toggle source
#

reset

#
Calls superclass method ImageParadise::Base#reset
# File lib/image_paradise/label/simple_label.rb, line 75
def reset
  super()
  @_           = ''.dup
  @label       = ''.dup
  @background  = 'lightblue'
  @fill        = 'blue'
  @font        = DEFAULT_FONT_TO_USE
  @pointsize   = '96'
  @output_file = 'label.'+DEFAULT_IMAGE_FORMAT.downcase
  set_size       '250x75'
end
run() click to toggle source
#

run

#
# File lib/image_paradise/label/simple_label.rb, line 195
def run
  build_up_main_command
  output_then_run_the_main_command
  consider_opening_in_the_browser
end
set_label(i) click to toggle source
#

set_label

#
# File lib/image_paradise/label/simple_label.rb, line 54
def set_label(i)
  if i.is_a? Array
    i = i.join(' ').strip
  end
  # ======================================================================= #
  # Check whether the label includes a Dimension. This may be a conflict
  # if the user REALLY wants to use some integer value, as part of the
  # given label - but aside from this, I think in most other cases,
  # this is a good default.
  # ======================================================================= #
  if i =~ REGEX_FOR_SIZE
    size_dimension = $1.to_s.dup
    set_size(size_dimension)
    i.sub!(/#{size_dimension}/,'')
  end
  @label = i
end
set_size(i = '250x75') click to toggle source
#

set_size

#
# File lib/image_paradise/label/simple_label.rb, line 90
def set_size(i = '250x75')
  @size = i.to_s
end