>>106275741
Convert image to grayscale, resize as needed, use grayscale image for alpha, then just write the data as color values.
import os, sys, math
from PIL import Image, ImageOps
if len(sys.argv) < 4:
print('Example: file2png input image out')
exit()
if not os.path.isfile(sys.argv[1]):
print('I can\'t find ' + sys.argv[1])
exit()
if not os.path.isfile(sys.argv[2]):
print('I can\'t find ' + sys.argv[2])
exit()
# load input
data = bytearray(open(sys.argv[1], 'rb').read())
# load overlay and convery to grayscale
overlayImg = Image.open(sys.argv[2])
overlayImg = ImageOps.grayscale(overlayImg)
# calculate width and height for output image in overlay's aspect ratio
pixelCnt = math.ceil(len(data)/3)
pixelCntRoot = pixelCnt**0.5
aspect = overlayImg.size[0] / overlayImg.size[1]
aspectRoot = aspect**0.5
width = math.ceil(pixelCntRoot * aspectRoot)
height = math.ceil(pixelCntRoot / aspectRoot)
# pad the input
padding = (width*height - pixelCnt)*3 + 3
data.extend([0] * padding)
# create image from data
dataImg = Image.frombytes('RGB', (width, height), bytes(data))
# scale overlay to match image from data
overlayImg = overlayImg.resize((width, height), Image.BICUBIC)
# split image channels
r, g, b = dataImg.split()
a = overlayImg.split()[0]
# change 0 alpha bytes into 1 alpha bytes to prevent optimization from removing rgb values
apixels = a.load()
for i in range(a.size[0]):
for j in range(a.size[1]):
if apixels[i,j] == 0:
apixels[i,j] = 1
# create output image using previously split channels
finalImg = Image.merge('RGBA', (r, g, b, a))
# save image
finalImg.save(sys.argv[3] + '.png')
(I didn't write the script.)