Skip to content

Instantly share code, notes, and snippets.

@Teinc3
Last active March 16, 2024 16:19
Show Gist options
  • Select an option

  • Save Teinc3/50bb11607e397374118d3e519eba4c21 to your computer and use it in GitHub Desktop.

Select an option

Save Teinc3/50bb11607e397374118d3e519eba4c21 to your computer and use it in GitHub Desktop.
ProTanki thumbnail blender

ProTanki Thumbnail Blender

Usage

$ python ptblender.py <colored_image_path> <alpha_image_path> <output_image_path>

External Dependencies

  • Pillow
$ pip install Pillow

OR

$ pip install -r requirements.txt
import os
import sys
from PIL import Image
def create_alpha_blend(colored_image_path, alpha_image_path, output_path):
colored_image_path = os.path.expanduser(colored_image_path)
alpha_image_path = os.path.expanduser(alpha_image_path)
output_path = os.path.expanduser(output_path)
colored_image = Image.open(colored_image_path)
alpha_image = Image.open(alpha_image_path).convert("L") # Convert to grayscale
# Ensure both images have the same size
if colored_image.size != alpha_image.size:
raise ValueError("Images must have the same dimensions")
# Create a new RGBA image with the same size
result = Image.new("RGBA", colored_image.size)
for x in range(colored_image.width):
for y in range(colored_image.height):
# Get the RGB values from the colored image
r, g, b = colored_image.getpixel((x, y))
# Get the alpha value from the alpha image
alpha_value = alpha_image.getpixel((x, y))
# Create a new RGBA pixel with the same RGB values and the alpha from the alpha image
result.putpixel((x, y), (r, g, b, alpha_value))
# Save the result
result.save(output_path, "PNG")
if __name__ == "__main__":
if len(sys.argv) != 4:
print("Usage: python ptblender.py <colored_image_path> <alpha_image_path> <output_image_path>")
sys.exit(1)
colored_image_path, alpha_image_path, output_path = sys.argv[1], sys.argv[2], sys.argv[3]
create_alpha_blend(colored_image_path, alpha_image_path, output_path)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment