python3 compatibility fixes

This commit is contained in:
Nick Zatkovich 2017-07-31 11:31:02 -07:00
parent 7251b14892
commit e9015b43b3
2 changed files with 9 additions and 9 deletions

View file

@ -21,17 +21,17 @@ image = Image.new("RGBA", background_image.size, (0, 0, 0, 0))
draw = ImageDraw.Draw(image) draw = ImageDraw.Draw(image)
txt1_size = draw.textsize(txt1, font=font) txt1_size = draw.textsize(txt1, font=font)
txt2_size = draw.textsize(txt2, font=font) txt2_size = draw.textsize(txt2, font=font)
draw.text((5, (image.height - txt1_size[1] - 5)), txt1, font=font, fill=(255,165,0,255)) draw.text((5, int(image.height - txt1_size[1] - 5)), txt1, font=font, fill=(255,165,0,255))
draw.text(((image.width - txt2_size[0] - 10), (image.height - txt2_size[1] - 5)), txt2, font=font, fill=(255,165,0,255)) draw.text((int(image.width - txt2_size[0] - 10), int(image.height - txt2_size[1] - 5)), txt2, font=font, fill=(255,165,0,255))
if len(sys.argv) > 3: if len(sys.argv) > 3:
#paste the other stuff onto the thing. #paste the other stuff onto the thing.
logo = Image.open(sys.argv[2]) logo = Image.open(sys.argv[2])
logo.load() logo.load()
phase = Image.open(sys.argv[3]) phase = Image.open(sys.argv[3])
phase.load() phase.load
image.paste(logo, ((image.width/2 - logo.width/2), 18)) image.paste(logo, ((int(image.width/2) - int(logo.width/2), 18)))
image.paste(phase, ((image.width/2 - phase.width/2), (image.height - logo.height - 10))) image.paste(phase, ((int(image.width/2) - int(phase.width/2)), int(image.height - phase.height - 30)))
outfile_name = sys.argv[4] outfile_name = sys.argv[4]
else: else:
outfile_name = sys.argv[2] outfile_name = sys.argv[2]

View file

@ -22,9 +22,9 @@ def image_tint(image, tint=None):
# create look-up tables to map luminosity to adjusted tint # create look-up tables to map luminosity to adjusted tint
# (using floating-point math only to compute table) # (using floating-point math only to compute table)
luts = (map(lambda lr: int(lr * sr + 0.5), range(256)) + luts = (tuple(map(lambda lr: int(lr * sr + 0.5), range(256))) +
map(lambda lg: int(lg * sg + 0.5), range(256)) + tuple(map(lambda lg: int(lg * sg + 0.5), range(256))) +
map(lambda lb: int(lb * sb + 0.5), range(256))) tuple(map(lambda lb: int(lb * sb + 0.5), range(256))))
l = ImageOps.grayscale(image) # 8-bit luminosity version of whole image l = ImageOps.grayscale(image) # 8-bit luminosity version of whole image
if Image.getmodebands(image.mode) < 4: if Image.getmodebands(image.mode) < 4:
merge_args = (image.mode, (l, l, l)) # for RGB verion of grayscale merge_args = (image.mode, (l, l, l)) # for RGB verion of grayscale
@ -32,7 +32,7 @@ def image_tint(image, tint=None):
a = Image.new("L", image.size) a = Image.new("L", image.size)
a.putdata(image.getdata(3)) a.putdata(image.getdata(3))
merge_args = (image.mode, (l, l, l, a)) # for RGBA verion of grayscale merge_args = (image.mode, (l, l, l, a)) # for RGBA verion of grayscale
luts += range(256) # for 1:1 mapping of copied alpha values luts += tuple(range(256)) # for 1:1 mapping of copied alpha values
return Image.merge(*merge_args).point(luts) return Image.merge(*merge_args).point(luts)