GeometrizeTwitterBot  1.0
Python Twitter bot for geometrizing images into geometric primitives
 All Classes Namespaces Files Functions Variables
Functions
geometrize Namespace Reference

Module that interfaces with the Geometrize executable, composing and executing scripts on it to geometrize images. More...

Functions

def _run_geometrize_code
 Executes the given script source code. More...
 
def _compose_image_path
 
def _load_image
 Loads up an image from the given filepath. More...
 
def run_geometrize
 Executes the given script source code. More...
 
def test_geometrize
 Performs some basic tests to ensure that Geometrize can run scripts and turn images into shapes properly. More...
 

Detailed Description

Module that interfaces with the Geometrize executable, composing and executing scripts on it to geometrize images.

Function Documentation

def geometrize._compose_image_path (   filename)
private
def _compose_image_path
Definition: geometrize.py:19
def get_geometrize_image_file_absolute_path
Composes an absolute path for an image file in the image data folder.
Definition: dependency_locator.py:36

Here is the call graph for this function:

Here is the caller graph for this function:

def geometrize._load_image (   filepath)
private

Loads up an image from the given filepath.

:return The loaded image, or None if the image failed to load.

24 
25 def _load_image(filepath):
26  image = None
27  print("Loading image from: " + filepath)
28  try:
29  image = Image.open(filepath)
30  except:
31  print("Failed to load image")
32  return image
def _load_image
Loads up an image from the given filepath.
Definition: geometrize.py:24

Here is the caller graph for this function:

def geometrize._run_geometrize_code (   code)
private

Executes the given script source code.

:return The Geometrize process return code, 0 indicates success.

14 
15 def _run_geometrize_code(code):
17  script_inline_flag = "--script_inline"
18  return call([executable_path, script_inline_flag, code])
def _run_geometrize_code
Executes the given script source code.
Definition: geometrize.py:14
def get_geometrize_executable_path
Gets the absolute path to where we expect to find the Geometrize executable.
Definition: dependency_locator.py:20

Here is the call graph for this function:

Here is the caller graph for this function:

def geometrize.run_geometrize (   code,
  tags = None 
)

Executes the given script source code.

:return True if the script executed successfully, else false.

35 
36 def run_geometrize(code, tags = None):
37  if tags is not None:
38  code = script_wrangler.replace_tags(code, tags)
39 
41  print("Script has template tags that have not been replaced, will fail rather than run script")
42  return False
43 
44  print("Will run script")
45  print(code)
46  ret_code = _run_geometrize_code(code)
47 
48  if ret_code != 0:
49  print("Failed to execute test script")
50  return False
51 
52  return True
def run_geometrize
Executes the given script source code.
Definition: geometrize.py:35
def _run_geometrize_code
Executes the given script source code.
Definition: geometrize.py:14
def code_contains_tags
Returns true if the given code contains any ::TAG::s, else false.
Definition: script_wrangler.py:27
def replace_tags
Replaces all instances of template ::TAG::s in the code from the given dictionary with their correspo...
Definition: script_wrangler.py:12

Here is the call graph for this function:

Here is the caller graph for this function:

def geometrize.test_geometrize ( )

Performs some basic tests to ensure that Geometrize can run scripts and turn images into shapes properly.

:return True if the tests executed successfully, else false.

55 
56 def test_geometrize():
57  print("Loading test script")
58  code = dependency_locator.read_geometrize_script("geometrize_test_script.chai")
59  if not code:
60  print("Failed to read test script, test will fail")
61  return False
62 
63  image_input_path = _compose_image_path("test_image_in.png")
64  image_output_path = _compose_image_path("test_image_out.png")
65 
66  print("Loading input image")
67  input_image = _load_image(image_input_path)
68  if input_image is None:
69  print("Failed to read the input image, test script will fail")
70  return False
71 
72  print("Replacing script tags")
73 
74  # Note that the backslashes in image paths need to be escaped, or just use forward slashes.
75  # This is because we are putting them into string literals in the scripts.
76  code = script_wrangler.replace_tag(code, "::IMAGE_INPUT_PATH::", image_input_path)
77  code = script_wrangler.replace_tag(code, "::IMAGE_OUTPUT_PATH::", image_output_path)
78 
80  print("Failed to replace all template tags in script, script will fail")
81  return False
82 
84  print("Failed to replace all template tags in script, script will fail")
85  return False
86 
87  ret_code = _run_geometrize_code(code)
88 
89  if ret_code != 0:
90  print("Failed to execute test script")
91  return False
92 
93  print("Checking if the test script saved the result image correctly")
94 
95  output_image = _load_image(image_output_path)
96  if output_image is None:
97  print("Failed to read the resulting geometrized image, test script will fail")
98  return False
99 
100  print("Printing input image to console\r\n")
102 
103  print("Printing Geometrized image to console\r\n")
105 
return True
def _load_image
Loads up an image from the given filepath.
Definition: geometrize.py:24
def _compose_image_path
Definition: geometrize.py:19
def read_geometrize_script
Reads a Chaiscript script file out of the Twitter bot scripts folder, returning the text content of t...
Definition: dependency_locator.py:57
def test_geometrize
Performs some basic tests to ensure that Geometrize can run scripts and turn images into shapes prope...
Definition: geometrize.py:55
def print_image_to_console
Definition: image_console_printer.py:82
def _run_geometrize_code
Executes the given script source code.
Definition: geometrize.py:14
def code_contains_tags
Returns true if the given code contains any ::TAG::s, else false.
Definition: script_wrangler.py:27
def replace_tag
Replaces all instances of a template ::TAG:: in the given code with the given value.
Definition: script_wrangler.py:8

Here is the call graph for this function: