BUILD: remove the last of the imagemagick stuff

The only remaining thing depending on imagemagick are the dist scripts
This commit is contained in:
Nick Zatkovich 2017-07-30 23:26:52 -07:00
parent 6724ef5aba
commit 215b7c644e
13 changed files with 149 additions and 182 deletions

View file

@ -16,3 +16,5 @@ credtext*.png
freettl.png
helptext*.png
wikilrs_horiz.png
fd?title.png
m_*.png

View file

@ -52,20 +52,20 @@ TEXTGEN_GRAPHIC_LUMPS = \
TEXTGEN_GRAPHICS = $(TEXTGEN_GRAPHIC_LUMPS) \
helpttl.png freettl.png
all: textgen.mk help.png credit.png wikilrs.png wivctms.png
all: text_strings help.png credit.png wikilrs.png wivctms.png titlepic
# Generate the menu and level strings
textgen.mk: config.py fontchars ../../lumps/dehacked.lmp
./textgen $@
text_strings: config.py fontchars ../../lumps/dehacked.lmp
python textgen.py
cp $(TEXTGEN_GRAPHIC_LUMPS) ../
# Background for the help screen is a color shifted version of INTERPIC:
helpbg.png: ../interpic.png
python tint.py ../interpic.png '#5599ff' helpbg.png
python tint.py ../interpic.png '#57b9b0' helpbg.png
# Generate transparent image containing text for the HELP screen:
help.png: helpttl.png helpbg.png
python smtextgen help.png 320x200 \
help.png: text_strings helpbg.png
python smtextgen.py help.png 320x200 \
-background "helpbg.png" \
150,5 "file:helpttl.png" \
10,25 "Weapons" \
@ -97,8 +97,8 @@ help.png: helpttl.png helpbg.png
128,107 "file:../../sprites/pstra0.png" \
170,115 "Armor" \
220,113 "file:../../sprites/bon2a0.png" \
240,105 "file:../../sprites/arm1b0.png" \
280,105 "file:../../sprites/arm2b0.png" \
240,113 "file:../../sprites/arm1b0.png" \
280,110 "file:../../sprites/arm2b0.png" \
145,140 "Map" \
175,130 "file:../../sprites/pmapa0.png" \
10,140 "Overdrive" \
@ -122,30 +122,47 @@ help.png: helpttl.png helpbg.png
cp $@ ../
credit.png: freettl.png helpbg.png credit.txt
python smtextgen credit.png 320x200 \
credit.png: text_strings helpbg.png credit.txt
python smtextgen.py credit.png 320x200 \
-background "helpbg.png" \
120,5 "file:freettl.png" \
10,30 "include:credit.txt"
cp $@ ../
wikilrs_horiz.png:
python smtextgen $@ 49x7 \
python smtextgen.py $@ 49x7 \
0,0 killers
wikilrs.png: wikilrs_horiz.png
python rotate.py wikilrs_horiz.png 90 $@
python rotate.py wikilrs_horiz.png -90 $@
cp $@ ../
wivctms.png:
python smtextgen $@ 54x7 \
python smtextgen.py $@ 54x7 \
0,0 victims
cp $@ ../
titlepic: fd1title.png fd2title.png fdmtitle.png
fd1title.png: text_strings ../titlepic/titlepic.png ../m_doom.png ../t_phase1.png
python create_caption.py ../titlepic/titlepic.png ../m_doom.png ../t_phase1.png $@
cp $@ ../
fd2title.png: text_strings ../titlepic/titlepic.png ../m_doom.png ../t_phase2.png
python create_caption.py ../titlepic/titlepic.png ../m_doom.png ../t_phase2.png $@
cp $@ ../
fdmtitle.png: ../titlepic/freedm_titlepic.png
python create_caption.py $< $@
cp $@ ../
clean:
rm -f $(TEXTGEN_GRAPHICS) helpbg.png help.png helptext.png \
helptext2.png graphics.stamp *.pyc credtext.png \
rm -f $(TEXTGEN_GRAPHICS) helpbg.png help.png \
graphics.stamp *.pyc credtext.png \
credtext.png credit.png dmwilv*.png wikilrs.png \
wivctms.png wikilrs_horiz.png ../credit.png ../help.png \
../wikilrs.png ../wivctms.png
../wikilrs.png ../wivctms.png \
fd1title.png fd2title.png fdmtitle.png \
../fd1title.png ../fd2title.png ../fdmtitle.png
for graphic in $(TEXTGEN_GRAPHICS); do rm -f ../$$graphic; done
rm -fr __pycache__

View file

@ -1,46 +0,0 @@
# SPDX-License-Identifier: BSD-3-Clause
import re
import subprocess
import sys
from PIL import Image
# Output from 'identify' looks like this:
# fontchars/font033.png GIF 9x16 9x16+0+0 8-bit sRGB 32c 194B 0.000u 0:00.000
IDENTIFY_OUTPUT_RE = re.compile(r'(\S+)\s(\S+)\s(\d+)x(\d+)(\+\d+\+\d+)?\s')
# Regexp to identify strings that are all lowercase (can use shorter height)
LOWERCASE_RE = re.compile(r'^[a-z\!\. ]*$')
def get_image_dimensions(filename):
"""Get image dimensions w x h
Args:
filename: filename of the image
"""
with Image.open(filename) as img:
width, height = img.size
return (width, height)
def invoke_command(command):
"""Invoke a command, printing the command to stdout.
Args:
command: Command and arguments as a list.
"""
for arg in command:
if arg.startswith('-'):
sys.stdout.write("\\\n ")
if ' ' in arg or '#' in arg:
sys.stdout.write(repr(arg))
else:
sys.stdout.write(arg)
sys.stdout.write(' ')
sys.stdout.write('\n')
return subprocess.call(command)

View file

@ -0,0 +1,40 @@
#!/usr/bin/env python
# coding=utf-8
from PIL import Image, ImageFont, ImageDraw
import sys
import os
#create_caption.py <background_image> <title?> <phase?> <outfile>
try:
font = ImageFont.truetype("DejaVuSansCondensed-Bold.ttf", 11)
except IOError:
font = ImageFont.load_default()
txt1= u"© 2001-2017"
txt2= os.environ['VERSION']
background_image = Image.open(sys.argv[1])
background_image.load()
background_image = background_image.convert("RGBA")
image = Image.new("RGBA", background_image.size, (0, 0, 0, 0))
draw = ImageDraw.Draw(image)
txt1_size = draw.textsize(txt1, 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(((image.width - txt2_size[0] - 10), (image.height - txt2_size[1] - 5)), txt2, font=font, fill=(255,165,0,255))
if len(sys.argv) > 3:
#paste the other stuff onto the thing.
logo = Image.open(sys.argv[2])
logo.load()
phase = Image.open(sys.argv[3])
phase.load()
image.paste(logo, ((image.width/2 - logo.width/2), 18))
image.paste(phase, ((image.width/2 - phase.width/2), (image.height - logo.height - 10)))
outfile_name = sys.argv[4]
else:
outfile_name = sys.argv[2]
image = Image.alpha_composite(background_image, image)
image.save(outfile_name)

View file

@ -0,0 +1,23 @@
# SPDX-License-Identifier: BSD-3-Clause
import re
from PIL import Image
def get_image_dimensions(filename):
"""Get image dimensions w x h
Args:
filename: filename of the image
"""
with Image.open(filename) as img:
width, height = img.size
return (width, height)
if __name__ == '__main__':
import sys
x,y = get_image_dimensions(sys.argv[1])
string = "%i %i" % (x, y)
sys.stdout.write(string)

View file

@ -9,7 +9,7 @@ from glob import glob
import sys
import re
from common import *
from image_dimensions import *
from tint import image_tint
# Background color for output files.
@ -108,41 +108,42 @@ def parse_command_line(args):
return result
if __name__ == '__main__':
args = parse_command_line(sys.argv[1:])
args = parse_command_line(sys.argv[1:])
if not args:
print("Usage: smtextgen <filename> <size> [...text commands...]")
print("Where each text command looks like:")
print(" [x,y] [text]")
sys.exit(0)
if not args:
print("Usage: smtextgen <filename> <size> [...text commands...]")
print("Where each text command looks like:")
print(" [x,y] [text]")
sys.exit(0)
smallfont = Font()
smallfont = Font()
if args['background'] is not None:
background_image = Image.open(args['background'])
background_image.load()
background_image = background_image.convert("RGBA")
if args['background'] is not None:
background_image = Image.open(args['background'])
background_image.load()
background_image = background_image.convert("RGBA")
image = Image.new("RGBA", args['dimensions'],(0,0,0,0))
image = Image.new("RGBA", args['dimensions'],(0,0,0,0))
for xy, string in args['strings']:
# Allow contents of a file to be included with special prefix:
if string.startswith(':'):
with open(string[8:]) as f:
string = f.read()
for xy, string in args['strings']:
# Allow contents of a file to be included with special prefix:
if string.startswith('include:'):
with open(string[8:]) as f:
string = f.read()
# Allow special notation to indicate an image file to just draw
# rather than rendering a string.
if string.startswith('file:'):
src_image = Image.open(string[5:])
src_image.load()
image.paste(src_image, (xy[0], xy[1]))
else:
smallfont.draw_for_text(image, string, xy[0], xy[1])
# Allow special notation to indicate an image file to just draw
# rather than rendering a string.
if string.startswith('file:'):
src_image = Image.open(string[5:])
src_image.load()
image.paste(src_image, (xy[0], xy[1]))
else:
smallfont.draw_for_text(image, string, xy[0], xy[1])
if args['background'] is not None:
image = Image.alpha_composite(background_image, image)
if args['background'] is not None:
image = Image.alpha_composite(background_image, image)
image.save(args['filename'])
image.save(args['filename'])

View file

@ -11,10 +11,10 @@ import re
import sys
from config import *
from common import *
from image_dimensions import *
from tint import image_tint
# ImageMagick -colorize parameters for colorizing text:
# Tinting parameters for colorizing text:
COLOR_BLUE = "#000001"
COLOR_RED = "#010000"
COLOR_WHITE = None
@ -31,6 +31,7 @@ UPPERCASE_FONT = False
# Width of a space character in pixels.
SPACE_WIDTH = 7
LOWERCASE_RE = re.compile(r'^[a-z\!\. ]*$')
class Font(object):
@ -109,8 +110,7 @@ class Font(object):
if c is None:
return x
def generate_graphic(self, text, output_filename,
color=COLOR_WHITE, bgcolor=BACKGROUND_COLOR):
def generate_graphic(self, text, color=COLOR_WHITE):
"""Get command to render text to a file
with the given background color.
"""
@ -136,15 +136,15 @@ class Font(object):
txt_image.paste(char_image, (x, height - FONT_HEIGHT))
txt_image = image_tint(txt_image, color)
txt_image.save(output_filename)
return txt_image
def generate_graphics(graphics, color=COLOR_WHITE, bgcolor=BACKGROUND_COLOR):
def generate_graphics(graphics, color=COLOR_WHITE):
for name, text in sorted(graphics.items()):
# write a makefile fragment
target = '%s.png' % name
font.generate_graphic(text, target,
color=color, bgcolor=bgcolor)
image = font.generate_graphic(text, color=color)
image.save(target)
def generate_kerning_test():
@ -158,12 +158,9 @@ def generate_kerning_test():
cmd = font.generate_graphic(" ".join(pairs), "kerning.png")
if __name__ == '__main__':
font = Font('fontchars', kerning_table=FONT_KERNING_RULES)
# Enable to generate test image file for tweaking kerning values:
#generate_kerning_test()
generate_graphics(red_graphics, color=COLOR_RED)
generate_graphics(blue_graphics, color=COLOR_BLUE)
generate_graphics(white_graphics, color=COLOR_WHITE)
font = Font('fontchars', kerning_table=FONT_KERNING_RULES)
generate_graphics(red_graphics, color=COLOR_RED)
generate_graphics(blue_graphics, color=COLOR_BLUE)
generate_graphics(white_graphics, color=COLOR_WHITE)

View file

@ -1,12 +1,10 @@
#/usr/bin/env python
# SPDX-License-Identifier: MIT
# Copyright (c) 2017 Martin Miller
# Copyright (c) 2017 Martin Miller, Nick Zatkovich
# https://stackoverflow.com/questions/12251896/colorize-image-while-preserving-transparency-with-pil
from PIL import Image
from ImageColor import getcolor, getrgb
from ImageOps import grayscale
from PIL import Image, ImageColor, ImageOps
def image_tint(image, tint=None):
if tint is None:
@ -14,8 +12,8 @@ def image_tint(image, tint=None):
if image.mode not in ['RGB', 'RGBA']:
image = image.convert('RGBA')
tr, tg, tb = getrgb(tint)
tl = getcolor(tint, "L") # tint color's overall luminosity
tr, tg, tb = ImageColor.getrgb(tint)
tl = ImageColor.getcolor(tint, "L") # tint color's overall luminosity
if not tl:
tl = 1 # avoid division by zero
tl = float(tl) # compute luminosity preserving tint factors
@ -27,7 +25,7 @@ def image_tint(image, tint=None):
luts = (map(lambda lr: int(lr * sr + 0.5), range(256)) +
map(lambda lg: int(lg * sg + 0.5), range(256)) +
map(lambda lb: int(lb * sb + 0.5), range(256)))
l = 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:
merge_args = (image.mode, (l, l, l)) # for RGB verion of grayscale
else: # include copy of image's alpha layer