class ImageParadise::RandomTextToImage

Constants

BE_VERBOSE
#

BE_VERBOSE

#
DEFAULT_FONT
#

DEFAULT_FONT

#
DEFAULT_FONT_SIZE
#

DEFAULT_FONT_SIZE

#
DEFAULT_TEXT
#

DEFAULT_TEXT

#
IMAGE_DIRECTORY
#

IMAGE_DIRECTORY

#
IMAGE_TYPE
#

IMAGE_TYPE

#
RUN_SYSTEM
#

RUN_SYSTEM

#
STORE_INTO_THIS_YAML_FILE
#

STORE_INTO_THIS_YAML_FILE

#

Attributes

be_verbose[W]

Public Class Methods

new( i = DEFAULT_TEXT, append_this_to_saved_filename = '', run_already = true, be_verbose = BE_VERBOSE ) click to toggle source
#

initialize

#
# File lib/image_paradise/utility_scripts/random_text_to_image.rb, line 58
def initialize(
    i                             = DEFAULT_TEXT,
    append_this_to_saved_filename = '',
    run_already                   = true,
    be_verbose                    = BE_VERBOSE
  )
  set_be_verbose(be_verbose)
  reset
  set_append_this_to_saved_filename(
    append_this_to_saved_filename
  )
  set_text(i)
  set_everything
  run if run_already
end

Public Instance Methods

get_random_colour() click to toggle source
#

get_random_colour

get random colours

#
# File lib/image_paradise/utility_scripts/random_text_to_image.rb, line 320
def get_random_colour
  Colours.html_colours?.sample
end
Also aliased as: random_colour
random_colour()
Alias for: get_random_colour
random_number(i = 20) click to toggle source
#

random_number

#
# File lib/image_paradise/utility_scripts/random_text_to_image.rb, line 221
def random_number(i = 20)
  rand(i)
end
Also aliased as: rd, random_plus
random_plus(i = 20)
Alias for: random_number
rd(i = 20)
Alias for: random_number
remove_old_image_file(i = @stored_where) click to toggle source
#

remove_old_image_file

#
# File lib/image_paradise/utility_scripts/random_text_to_image.rb, line 311
def remove_old_image_file(i = @stored_where)
  FileUtils.remove(i) if File.exist? i
end
report_where_we_stored_it() click to toggle source
#

report_where_we_stored_it

#
# File lib/image_paradise/utility_scripts/random_text_to_image.rb, line 258
def report_where_we_stored_it
  e 'Stored at `'+sfile(@stored_where)+'`.'
end
reset() click to toggle source
#

reset (reset tag)

#
# File lib/image_paradise/utility_scripts/random_text_to_image.rb, line 77
def reset # reset @_ again.
  @_ = 'convert '.dup
end
run() click to toggle source
#

run

#
# File lib/image_paradise/utility_scripts/random_text_to_image.rb, line 353
def run # bundle some methods together (run tag).
  run_sys_cmd
  store_last_command_into_yaml_file
  report_where_we_stored_it
end
run_n_times( n_times = HOW_MANY_TIMES ) click to toggle source
#

run_n_times

#
# File lib/image_paradise/utility_scripts/random_text_to_image.rb, line 115
def run_n_times(
    n_times = HOW_MANY_TIMES
  ) # use this to create not one but several images.
  n_times.times { |t|
    reset
    set_append_this_to_saved_filename(t+1)
    set_everything
    run
  }
end
run_sys_cmd() click to toggle source
#

run_sys_cmd

#
# File lib/image_paradise/utility_scripts/random_text_to_image.rb, line 327
def run_sys_cmd
  remove_old_image_file # remove the image file if it exsts.
  if @be_verbose
    opn; e N+YEL+'Running this convert command next:'
    e '  '+@_
  end
  system @_ if run_system?
end
run_system?() click to toggle source
#

run_system?

#
# File lib/image_paradise/utility_scripts/random_text_to_image.rb, line 346
def run_system?
  RUN_SYSTEM
end
set_append_this_to_saved_filename(i) click to toggle source
#

set_append_this_to_saved_filename

#
# File lib/image_paradise/utility_scripts/random_text_to_image.rb, line 129
def set_append_this_to_saved_filename(i)
  @append_this_to_saved_filename = i.to_s
end
set_background_colour() click to toggle source
#

set_background_colour

#
# File lib/image_paradise/utility_scripts/random_text_to_image.rb, line 213
def set_background_colour # background tag.
  @_ << ' -background '
  @_ << 'black'
end
set_be_verbose(i) click to toggle source
#

set_be_verbose

#
# File lib/image_paradise/utility_scripts/random_text_to_image.rb, line 84
def set_be_verbose(i) # Setter for @be_verbose.
  @be_verbose = i
end
set_blur() click to toggle source
#

set_blur

#
# File lib/image_paradise/utility_scripts/random_text_to_image.rb, line 272
def set_blur
  i = ( 0+random_plus(5) ).to_s 
  @_ << ' -blur 0x'+i
end
set_border() click to toggle source
#

set_border

#
# File lib/image_paradise/utility_scripts/random_text_to_image.rb, line 229
def set_border
  n = random_number.to_s
  @_ << ' -border '+n+'x'+n
  @_ << ' -bordercolor '+random_colour 
end
set_canvas() click to toggle source
#

set_canvas

#
# File lib/image_paradise/utility_scripts/random_text_to_image.rb, line 199
def set_canvas
  @_ << ' canvas:none'
end
set_channel() click to toggle source
#

set_channel

#
# File lib/image_paradise/utility_scripts/random_text_to_image.rb, line 280
def set_channel
  @_ << ' -channel RGBA'
end
set_draw1() click to toggle source
#

set_draw1

#
# File lib/image_paradise/utility_scripts/random_text_to_image.rb, line 176
def set_draw1 # this is the draw for text.
  _ = "'"+@text+"'"
  @_ << ' -draw "text '+@width+','+@height+' '+_+'"'
end
set_draw2() click to toggle source
#

set_draw2

#
# File lib/image_paradise/utility_scripts/random_text_to_image.rb, line 184
def set_draw2 # This is the draw for -stroke
  _ = "'"+@text+"'"
  @_ << ' -draw "text 20,'+DEFAULT_FONT_SIZE+' '+_+'"'
end
set_everything() click to toggle source
#

set_everything

#
# File lib/image_paradise/utility_scripts/random_text_to_image.rb, line 136
def set_everything # wrapper to set everything.
  random_plus = rd(225)
  set_width
  set_height
  set_size(
    @width.to_i  * 8+random_plus,
    @height.to_i * 7+random_plus
  )
  set_canvas
  set_font
  set_pointsize
  set_draw1
  set_channel
  set_blur
  set_transparent # if we want a transparent background.
  # set_background_colour
  set_fill
  set_stroke
  set_draw2
  # set_border # Something is weird here.
  set_name # This here should come right before run_sys_cmd is called.
end
set_fill(which_colour = get_random_colour) click to toggle source
#

set_fill

#
# File lib/image_paradise/utility_scripts/random_text_to_image.rb, line 192
def set_fill(which_colour = get_random_colour)
  @_ << ' -fill '+which_colour
end
set_font(this_font = DEFAULT_FONT) click to toggle source
#

set_font

#
# File lib/image_paradise/utility_scripts/random_text_to_image.rb, line 294
def set_font(this_font = DEFAULT_FONT)
  this_font = '"'+this_font.to_s+'"' # Pad this first.
  @_ << ' -font '+this_font
end
set_height() click to toggle source
#

set_height

#
# File lib/image_paradise/utility_scripts/random_text_to_image.rb, line 169
def set_height
  @height = ( 25+random_number(6) ).to_s
end
set_name( this_name = 'output' ) click to toggle source
#

set_name

#
# File lib/image_paradise/utility_scripts/random_text_to_image.rb, line 245
def set_name(
    this_name = 'output'
  )
  this_name = this_name.dup if this_name.frozen?
  this_name << @append_this_to_saved_filename
  this_name << IMAGE_TYPE
  @stored_where = IMAGE_DIRECTORY+'/'+this_name# keep a reference where it is stored.
  @_ << ' '+@stored_where
end
set_pointsize(i = 12+random_plus(75)) click to toggle source
#

set_pointsize

#
# File lib/image_paradise/utility_scripts/random_text_to_image.rb, line 287
def set_pointsize(i = 12+random_plus(75))
  @_ << ' -pointsize '+i.to_s
end
set_size(width = 500, height = 500) click to toggle source
#

set_size

This method will set the size of the canvas.

#
# File lib/image_paradise/utility_scripts/random_text_to_image.rb, line 304
def set_size(width = 500, height = 500)
  @_ << "-size #{width}x#{height}" 
end
set_stroke() click to toggle source
#

set_stroke

#
# File lib/image_paradise/utility_scripts/random_text_to_image.rb, line 265
def set_stroke
  @_ << ' -stroke '+random_colour
end
set_text(i = DEFAULT_TEXT) click to toggle source
#

set_text

#
# File lib/image_paradise/utility_scripts/random_text_to_image.rb, line 91
def set_text(i = DEFAULT_TEXT) # this sets the @text variable.
  _ = STORE_INTO_THIS_YAML_FILE
  if i.is_a? Array
    if i.empty?
      i = DEFAULT_TEXT
    else
      i = i.join(' ').strip
    end
  end
  i = DEFAULT_TEXT if i.nil?
  if i == 'LAST' # treat LAST as special instruction.
    if File.exist? _
      i = YAML.load_file(_)
    else
      opn; e 'Sorry, file '+sfile(_)+' does not exist.'
    end
  end
  i.gsub!("'", "\\\\'") if i.include? "'"
  @text = i
end
set_transparent() click to toggle source
#

set_transparent

#
# File lib/image_paradise/utility_scripts/random_text_to_image.rb, line 206
def set_transparent
  @_ << ' -transparent white'
end
set_width() click to toggle source
#

set_width

#
# File lib/image_paradise/utility_scripts/random_text_to_image.rb, line 162
def set_width
  @width = ( 25+random_number(6) ).to_s
end
store_last_command_into_yaml_file() click to toggle source
#

store_last_command_into_yaml_file

#
# File lib/image_paradise/utility_scripts/random_text_to_image.rb, line 238
def store_last_command_into_yaml_file
  File.open(STORE_INTO_THIS_YAML_FILE, 'w') {|f| YAML.dump(@text,f)} 
end
stored_where()
Alias for: stored_where?
stored_where?() click to toggle source
#

stored_where?

#
# File lib/image_paradise/utility_scripts/random_text_to_image.rb, line 339
def stored_where?
  @stored_where
end
Also aliased as: stored_where