def ConvertToBitifiedImage(file_location,
                           thumbnail_width=settings.THUMBNAIL_WIDTH,
                           final_width=settings.FINAL_WIDTH,
                           bit_depth=settings.BIT_DEPTH):
  # Load image from file location
  image = Image.open(file_location).convert('RGB')

  # If image is JPG/GIF perform extra processing to image
  if image.format == 'JPG':
    image = ImageOps.autocontrast(image)
  elif image.format == 'GIF':
    # Need to equalize to change gif to something that can be converted.
    image = ImageOps.equalize(image)

  # Blur image and reduce number of colors to bit_depth
  image = image.convert('P',
                        palette=Image.ADAPTIVE,
                        colors=bit_depth).convert('RGB')

  processed_image = image.copy()

  # Keep only most common color in large area
  processed_image = processed_image.filter(ImageFilter.BLUR)

  # Low-pass filter
  for x in xrange(processed_image.size[0]):
    for y in xrange(processed_image.size[1]):
      r, g, b = processed_image.getpixel((x, y))
      if r < 50 and g < 50 and b < 50:
        processed_image.putpixel((x, y), (0, 0, 0))
      else:
        processed_image.putpixel((x, y), (r, g, b))

  # Set final width to at most final_width
  width, height = processed_image.size
  final_width = min(width, final_width)

  # Add border to image before shrinking
  processed_image = AddBorderToImage(processed_image)

  thumbnail_size = thumbnail_width, thumbnail_width * height/width
  final_size = final_width, final_width * height/width
  # Shrink image while keeping aspect ratio
  processed_image.thumbnail(thumbnail_size, Image.ADAPTIVE)
  # Resize back, resulting in pixelized image
  processed_image = processed_image.resize(final_size, Image.NEAREST)
  # Back to RGB format
  processed_image = processed_image.convert('RGB',
                                            palette=Image.ADAPTIVE,
                                            colors=bit_depth)

  # Add a random quote to the image
  processed_image = AddRandomTextToImage(processed_image)

  return processed_image
Loads image from filename, generates bitified Image and returns it.
dataset/ETHPy150Open GoogleCloudPlatform/solutions-orchestrator-android-sampleapp-smashpix/daemon/image_processing.py/ConvertToBitifiedImage