From 0d6bb9fc721efe08f99bc384c81e4a898e601888 Mon Sep 17 00:00:00 2001 From: Mike Swanson Date: Mon, 31 Jul 2017 16:41:07 -0700 Subject: [PATCH] dist: Use Pillow to generate application icons. --- dist/Makefile | 11 +++-------- dist/pillow-compose | 26 ++++++++++++++++++++++++++ dist/pillow-resize | 11 +++++++++++ 3 files changed, 40 insertions(+), 8 deletions(-) create mode 100755 dist/pillow-compose create mode 100755 dist/pillow-resize diff --git a/dist/Makefile b/dist/Makefile index 2a6dee0e..02c495f6 100644 --- a/dist/Makefile +++ b/dist/Makefile @@ -3,18 +3,13 @@ man-%: freedoom.adoc a2x -f manpage $*.adoc icon-freedm: - convert -resize 64x64 ../graphics/titlepic/freedm_title2.png \ - freedm.png + ./pillow-resize ../graphics/titlepic/freedm_title2.png freedm.png 64 64 icon-freedoom1: - convert -trim +repage -extent 48x48 -gravity center \ - -transparent \#00ffff -background \#00ffff \ - ../sprites/playa2a8.png freedoom1.png + ./pillow-compose ../sprites/playa2a8.png freedoom1.png 64 64 icon-freedoom2: - convert -trim +repage -extent 64x64 -gravity center \ - -transparent \#00ffff -background \#00ffff \ - ../sprites/heada1.png freedoom2.png + ./pillow-compose ../sprites/heada1.png freedoom2.png 64 64 clean: rm -f *.6 *.png freedm.adoc freedoom1.adoc freedoom2.adoc diff --git a/dist/pillow-compose b/dist/pillow-compose new file mode 100755 index 00000000..6ae25846 --- /dev/null +++ b/dist/pillow-compose @@ -0,0 +1,26 @@ +#!/usr/bin/env python + +# Simple and dumb Pillow-based compositor +# Usage: pillow-compose src-img.png dst-img.png WIDTH HEIGHT + +import sys +from PIL import Image + +src = Image.open(sys.argv[1]) +img = Image.new('RGBA', (int(sys.argv[3]), int(sys.argv[4])), (0, 0, 0, 0)) + +# Pillow's compositing won't accept negative values. This can happen +# if the destination image is smaller on at least on axis than the +# source image. +if img.size[0] - src.size[0] < 0: + off_x = 0 +else: + off_x = (img.size[0] - src.size[0]) // 2 + +if img.size[1] - src.size[1] < 0: + off_y = 0 +else: + off_y = (img.size[1] - src.size[1]) // 2 + +img.alpha_composite(src.convert('RGBA'), (off_x, off_y)) +img.save(sys.argv[2]) diff --git a/dist/pillow-resize b/dist/pillow-resize new file mode 100755 index 00000000..154f7cb8 --- /dev/null +++ b/dist/pillow-resize @@ -0,0 +1,11 @@ +#!/usr/bin/env python + +# Simple and dumb Pillow-based resizer +# Usage: pillow-resize src-img.png dst-img.png WIDTH HEIGHT + +import sys +from PIL import Image + +img = Image.open(sys.argv[1]) +img.thumbnail((int(sys.argv[3]), int(sys.argv[4]))) +img.save(sys.argv[2])