def __init__(self, imagepath):
   # Base options
   self.base_image = ImageManager.newFromPath(imagepath)
   self.base_image.load()
   self.colours = None
   self.collage_image = CollageImage.new(self.base_image.size)
   self.output_image_savepath = None
   self.images_folder = None
   self.debug = False
   self.log = None
   # Collage options
   self.precision = DEFAULT_PRECISION
   self.threshold = DEFAULT_THRESHOLD
   self.near_size = DEFAULT_NEAR_SIZE
   self.scale_factor = 1
   self.shuffle_colours = False
   self.shuffle_colours_distance = DEFAULT_SHUFFLE_COLOURS_DISTANCE
   self.shuffle_geometry = DEFAULT_SHUFFLE_GEOMETRY
   # Workflow options
   self.show_partials = False
   # Class variables
   self.sector_size = None
   self.collage_image_size = None
   self.collage_image_size_precision = DEFAULT_COLLAGE_IMAGE_SIZE_PRECISION
   self.collage_image_size_min = None # Enforced limit
   self.collage_image_size_max_width = None # Non-enforced limit
   self.collage_image_size_max_height = None # Non-enforced limit
   # Collage variables
   self.collage_same_height_streak = DEFAULT_COLLAGE_SAME_HEIGHT_STREAK
   self.collage_same_height_streak_max = DEFAULT_COLLAGE_SAME_HEIGHT_STREAK
 def loadColoursComplete(self):
   self.log.info('loadColoursComplete == Loading colours')
   self.log.debug('loadColoursComplete == Collage image size: ' + str(self.collage_image_size))
   self.log.debug('loadColoursComplete == Collage image size precision: ' + str(self.collage_image_size_precision))
   self.log.debug('loadColoursComplete == Sector size: ' + str(self.sector_size))
   # Set min size
   self.collage_image_size_min = int(numpy.ceil(self.collage_image_size * self.collage_image_size_precision))
   self.log.info('loadColoursComplete == Min size: ' + str(self.collage_image_size_min))
   # Save width and height
   images_width = []
   images_height = []
   print('Loading resources')
   self.log.info('loadColoursComplete == Loading from images')
   loading_folder = self.images_folder
   for name in os.listdir(loading_folder):
     path = os.path.join(loading_folder, name)
     if not os.path.isdir(path) and self.hasValidExtension(path): # Ignore folders and invalid files
       try:
         img = ImageManager.new(path)
         img.setSectorSize(self.sector_size)
         # resize
         img.resizeMaximal(self.collage_image_size)
         # partition
         img.partition()
         # load colour
         colour = CollageImage.newColour(img, self.sector_size)
         # add to self.colours
         self.colours.append(colour)
         # add sizes
         images_width.append(img.width)
         images_height.append(img.height)
         # Show progress
         sys.stdout.write('.')
         sys.stdout.flush()
       except Exception as error:
         self.log.info('loadColoursComplete == Error loading: ' + path)
         print('\n*Error loading ' + path)
         continue
   self.collage_image_size_avg_width = int(numpy.ceil(numpy.mean(images_width)))
   self.collage_image_size_avg_height = int(numpy.ceil(numpy.mean(images_height)))
   self.collage_image_size_max_width = int(numpy.max(images_width))
   self.collage_image_size_max_height = int(numpy.max(images_height))
   self.log.info('loadColoursComplete == Collage image size avg width: ' + str(self.collage_image_size_avg_width))
   self.log.info('loadColoursComplete == Collage image size avg height: ' + str(self.collage_image_size_avg_height))
   self.log.info('loadColoursComplete == Collage image size max width: ' + str(self.collage_image_size_max_width))
   self.log.info('loadColoursComplete == Collage image size max height: ' + str(self.collage_image_size_max_height))
   print('\nLoaded ' + str(len(self.colours)) + ' resources')
 def getResizedImage(self, size, antialias=False, partition=True, memorize=True):
   width, height = size
   if size in self.images:
     img = self.images[width, height]
     img.setSectorSize(self.sector_size)
     if partition and not img.isPartitioned():
       img.partition()
   else:
     img_raw = self.base_img.getResizedCopy(size, antialias)
     img = ImageManager.newFromData(img_raw)
     img.setSectorSize(self.sector_size)
     if partition:
       img.partition()
     if memorize and MAX_IMAGES_MEM > 0:
       if len(self.images) > MAX_IMAGES_MEM:
         # delete one element
         del_key = list(self.images.keys())[0]
         del self.images[del_key]
       # Add this image
       self.images[width, height] = img
   return img
 def reload(self):
   self.images = {}
   imgpath = self.base_img.getFilepath()
   self.base_img = ImageManager.newFromPath(imgpath)
def newColourFromPath(imgpath, sector_size=None):
  img = ImageManager.newFromPath(imgpath)
  colour = CollageColour(img, sector_size)
  return colour