class ImageParadise::TextOnImage

Constants

NAMESPACE
#

NAMESPACE

#

Public Class Methods

new( i = ARGV, run_already = true ) { || ... } click to toggle source
#

initialize

#
# File lib/image_paradise/utility_scripts/text_on_image.rb, line 30
def initialize(
    i           = ARGV,
    run_already = true
  )
  reset
  set_commandline_arguments(i)
  # ======================================================================= #
  # === Handle blocks next
  # ======================================================================= #
  if block_given?
    yielded = yield
    case yielded
    # ===================================================================== #
    # === :do_not_run_yet
    # ===================================================================== #
    when :do_not_run_yet
      run_already = false
    end
  end
  run if run_already
end

Public Instance Methods

colour_to_use?() click to toggle source
#

colour_to_use?

#
# File lib/image_paradise/utility_scripts/text_on_image.rb, line 106
def colour_to_use?
  _ = ::ImageParadise.default_colour?
  if @internal_hash[:use_this_colour]
    _ = @internal_hash[:use_this_colour]
  end
  return _.to_s
end
coordinates?() click to toggle source
#

coordinates?

#
# File lib/image_paradise/utility_scripts/text_on_image.rb, line 133
def coordinates?
  @internal_hash[:use_this_position].to_s
end
determine_on_which_files_to_act() click to toggle source
#

determine_on_which_files_to_act

#
# File lib/image_paradise/utility_scripts/text_on_image.rb, line 87
def determine_on_which_files_to_act
  @internal_hash[:work_on_these_files] = commandline_arguments?.select {|entry|
    File.exist?(entry)
  }
end
do_process_the_given_files( _ = @internal_hash[:work_on_these_files] ) click to toggle source
#

do_process_the_given_files

#
# File lib/image_paradise/utility_scripts/text_on_image.rb, line 275
def do_process_the_given_files(
    _ = @internal_hash[:work_on_these_files]
  )
  unless _.empty?
    _.each {|work_on_this_file|
      cmd_to_use = ''.dup
      cmd_to_use << 'convert '
      if size? and !size?.empty?
        cmd_to_use << "-pointsize #{size?} "
      end
      if colour_to_use? and !colour_to_use?.empty?
        cmd_to_use << "-fill #{colour_to_use?} "
      end
      # =================================================================== #
      # Next let's draw the text.
      # =================================================================== #
      cmd_to_use << '-draw "text '+coordinates?+" '"+text?+"'"+'" '
      cmd_to_use << "#{work_on_this_file} "
      if strokewidth?
        cmd_to_use << '-strokewidth '+strokewidth?.to_s+' '
      end
      cmd_to_use << 'output_file.png'
      esystem(cmd_to_use.squeeze(' '))
    }
  end if _
end
menu( i = commandline_arguments? )
notify_the_user_whether_any_file_could_be_found_or_not() click to toggle source
#

notify_the_user_whether_any_file_could_be_found_or_not

#
# File lib/image_paradise/utility_scripts/text_on_image.rb, line 96
def notify_the_user_whether_any_file_could_be_found_or_not
  _ = @internal_hash[:work_on_these_files]
  if _.empty?
    opnn; e 'No existing file could be found.'
  end
end
parse_the_hyphened_commandline_arguments( i = commandline_arguments? ) click to toggle source
#

parse_the_hyphened_commandline_arguments (menu tag)

#
# File lib/image_paradise/utility_scripts/text_on_image.rb, line 173
def parse_the_hyphened_commandline_arguments(
    i = commandline_arguments?
  )
  html_colours = Colours.html_colours.map {|entry| Regexp.new("^-?-?#{entry}$") }
  i.select {|entry| entry.start_with? '--' }.each {|entry|
    case entry
    # ===================================================================== #
    # === --darkblue
    # ===================================================================== #
    when *html_colours
      set_use_this_colour(entry)
    # ===================================================================== #
    # === --strokewidth="abc def"
    # ===================================================================== #
    when /^-?-?strokewidth=(.+)/
      set_use_this_strokewidth($1)
    # ===================================================================== #
    # === --text="abc def"
    # ===================================================================== #
    when /^-?-?text=(.+)/
      set_use_this_text($1)
    # ===================================================================== #
    # === --colour=steelblue
    # ===================================================================== #
    when /^-?-?colou?r=(.+)/
      set_use_this_colour($1)
    # ===================================================================== #
    # === --font-size=3
    # ===================================================================== #
    when /^-?-?font(-|_)size=(.+)/ # We grab the second entry here.
      set_use_this_font_size($2)
    # ===================================================================== #
    # === --position=3
    # ===================================================================== #
    when /^-?-?position=(.+)/
      set_use_this_position($1)
    else
      if File.exist? entry
        # ================================================================= #
        # Existing local files will be captured here.
        # ================================================================= #
        set_filename(entry)
      end
    end
  }
  i.each {|entry| set_filename(entry) if File.exist?(entry) }
end
Also aliased as: menu
reset() click to toggle source
#

reset (reset tag)

#
# File lib/image_paradise/utility_scripts/text_on_image.rb, line 55
def reset
  # ======================================================================= #
  # === @namespace
  # ======================================================================= #
  @namespace = NAMESPACE
  # ======================================================================= #
  # === @internal_hash
  # ======================================================================= #
  @internal_hash = {}
  # ======================================================================= #
  # === :write_this_text
  #
  # This variable keeps track as to which text is to be written.
  # ======================================================================= #
  @internal_hash[:write_this_text] = ''.dup
  # ======================================================================= #
  # === :use_this_colour
  # ======================================================================= #
  @internal_hash[:use_this_colour] = nil
  # ======================================================================= #
  # === :strokewidth
  # ======================================================================= #
  @internal_hash[:strokewidth] = nil
  # ======================================================================= #
  # Set up some default values next past this point.
  # ======================================================================= #
  set_use_this_position
end
run() click to toggle source
#

run

#
# File lib/image_paradise/utility_scripts/text_on_image.rb, line 305
def run
  determine_on_which_files_to_act
  parse_the_hyphened_commandline_arguments
  notify_the_user_whether_any_file_could_be_found_or_not
  do_process_the_given_files
end
set_file(i)
Alias for: set_files
set_filename(i)
Alias for: set_files
set_files(i) click to toggle source
#

set_files

#
# File lib/image_paradise/utility_scripts/text_on_image.rb, line 238
def set_files(i)
  @internal_hash[:work_on_these_files] = [i].flatten.compact
end
Also aliased as: set_file, set_filename
set_font_size(i = :default)
set_text( i, optional_change_stuff = nil )
Alias for: set_use_this_text
set_use_this_colour(i) click to toggle source
#

set_use_this_colour

#
# File lib/image_paradise/utility_scripts/text_on_image.rb, line 246
def set_use_this_colour(i)
  @internal_hash[:use_this_colour] = i.to_s.dup.delete('-')
end
set_use_this_font_size(i = :default) click to toggle source
#

set_use_this_font_size

#
# File lib/image_paradise/utility_scripts/text_on_image.rb, line 261
def set_use_this_font_size(i = :default)
  case i
  # ======================================================================= #
  # === :default
  # ======================================================================= #
  when :default
    i = 35
  end
  @internal_hash[:use_this_font_size] = i.to_s.dup.to_i
end
Also aliased as: set_font_size
set_use_this_position( i = :default ) click to toggle source
#

set_use_this_position

#
# File lib/image_paradise/utility_scripts/text_on_image.rb, line 117
def set_use_this_position(
    i = :default
  )
  case i
  # ======================================================================= #
  # === :default
  # ======================================================================= #
  when :default
    i = ::ImageParadise.default_position?
  end
  @internal_hash[:use_this_position] = i.to_s.dup
end
set_use_this_strokewidth(i) click to toggle source
#

set_use_this_strokewidth

#
# File lib/image_paradise/utility_scripts/text_on_image.rb, line 224
def set_use_this_strokewidth(i)
  @internal_hash[:strokewidth] = i.to_s.dup
end
set_use_this_text( i, optional_change_stuff = nil ) click to toggle source
#

set_use_this_text

#
# File lib/image_paradise/utility_scripts/text_on_image.rb, line 147
def set_use_this_text(
    i, optional_change_stuff = nil
  )
  if i.is_a? Array
    case optional_change_stuff
    # ===================================================================== #
    # === :without_hyphened_arguments
    # ===================================================================== #
    when :without_hyphened_arguments
      i = i.reject {|entry| entry.start_with?('--') }
    end
    i = i.join(' ')
  end
  @internal_hash[:write_this_text] = i.to_s.dup
end
Also aliased as: set_text
size?() click to toggle source
#

size?

#
# File lib/image_paradise/utility_scripts/text_on_image.rb, line 140
def size?
  @internal_hash[:use_this_font_size].to_s
end
strokewidth?() click to toggle source
#

strokewidth?

#
# File lib/image_paradise/utility_scripts/text_on_image.rb, line 231
def strokewidth?
  @internal_hash[:strokewidth]
end
text?() click to toggle source
#

text?

#
# File lib/image_paradise/utility_scripts/text_on_image.rb, line 166
def text?
  @internal_hash[:write_this_text]
end
use_default_colour() click to toggle source
#

use_default_colour

#
# File lib/image_paradise/utility_scripts/text_on_image.rb, line 253
def use_default_colour
  ::ImageParadise.default_colour = :default
  set_use_this_colour(::ImageParadise.default_colour?)
end