mirror of
https://github.com/freedoom/freedoom.git
synced 2025-09-05 07:25:45 -04:00
textgen: alpha_composite instead of paste
pasting with kerning cut off some of the letters
This commit is contained in:
parent
dfde6e8793
commit
648f6aebe9
2 changed files with 13 additions and 3 deletions
|
@ -72,9 +72,16 @@ class Font(object):
|
||||||
|
|
||||||
filename = self.char_filename(c)
|
filename = self.char_filename(c)
|
||||||
char_image = Image.open(filename)
|
char_image = Image.open(filename)
|
||||||
image.paste(char_image, (x1, y1))
|
char_image.load()
|
||||||
|
self.paste_image(image, char_image, x1, y1)
|
||||||
x1 += self.char_width(c)
|
x1 += self.char_width(c)
|
||||||
|
|
||||||
|
def paste_image(self, image, src, x, y):
|
||||||
|
int_image = Image.new("RGBA", image.size, (0, 0, 0, 0))
|
||||||
|
int_image.paste(src, (x, y))
|
||||||
|
image = Image.alpha_composite(image, int_image)
|
||||||
|
|
||||||
|
|
||||||
def parse_command_line(args):
|
def parse_command_line(args):
|
||||||
if len(args) < 4 or (len(args) % 2) != 0:
|
if len(args) < 4 or (len(args) % 2) != 0:
|
||||||
return None
|
return None
|
||||||
|
@ -108,6 +115,7 @@ def parse_command_line(args):
|
||||||
|
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|
||||||
args = parse_command_line(sys.argv[1:])
|
args = parse_command_line(sys.argv[1:])
|
||||||
|
@ -138,7 +146,7 @@ if __name__ == '__main__':
|
||||||
if string.startswith('file:'):
|
if string.startswith('file:'):
|
||||||
src_image = Image.open(string[5:])
|
src_image = Image.open(string[5:])
|
||||||
src_image.load()
|
src_image.load()
|
||||||
image.paste(src_image, (xy[0], xy[1]))
|
smallfont.paste_image(image, src_image, xy[0], xy[1])
|
||||||
else:
|
else:
|
||||||
smallfont.draw_for_text(image, string, xy[0], xy[1])
|
smallfont.draw_for_text(image, string, xy[0], xy[1])
|
||||||
|
|
||||||
|
|
|
@ -133,7 +133,9 @@ class Font(object):
|
||||||
filename = self.char_filename(c)
|
filename = self.char_filename(c)
|
||||||
char_image = Image.open(filename)
|
char_image = Image.open(filename)
|
||||||
char_image.load()
|
char_image.load()
|
||||||
txt_image.paste(char_image, (x, height - FONT_HEIGHT))
|
int_image = Image.new("RGBA", txt_image.size, (0, 0, 0, 0))
|
||||||
|
int_image.paste(char_image, (x, height - FONT_HEIGHT))
|
||||||
|
txt_image = Image.alpha_composite(txt_image, int_image)
|
||||||
|
|
||||||
txt_image = image_tint(txt_image, color)
|
txt_image = image_tint(txt_image, color)
|
||||||
return txt_image
|
return txt_image
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue