2020-10-27 18:36:29

Hello all,
Something a little different today:

While fighting once again with the Google Play store, I find myself needing images, logos and featured images and the like.

The app I'm uploading has been written for blind people. The text in it wraps horribly, it's never going to be used by anyone with an ounce of interest in the aesthetic, so quite frankly, I've got better things to do with my life than get hot and steamy with someone who can create images.

A quick google turned up this page. I'm not going to bother rehashing what it says already, you can go read it if you care. I will however give you my new logo-generating script.

It's not been linted in any way, but I've successfully generated the two images I needed it for, so I'll not be doing anything more than that.

Here's the code: txt2img.py.

from argparse import ArgumentParser, FileType

from PIL import Image, ImageDraw

parser = ArgumentParser()

parser.add_argument('width', type=int, help='The width of the new image')
parser.add_argument('height', type=int, help='The height of the new image')
parser.add_argument('text', help='The text to render on the image')
parser.add_argument('--bg', default='white', help='Background colour')
parser.add_argument('-x', '--text-x', type=int, default=10, help='The upper x coordinate of the text')
parser.add_argument('-y', '--text-y', type=int, default=10, help='The upper y coordinate of the text')
parser.add_argument('--fg', default='black', help='Text folour')
parser.add_argument('-f', '--filename', type=FileType('wb'), default='image.png', help='Where to save the image')

if __name__ == '__main__':
    args = parser.parse_args()
    i = Image.new('RGB', (args.width, args.height), color=args.bg)
    d = ImageDraw.Draw(i)
    d.text((args.text_x, args.text_y), args.text, fill=args.fg)
    i.save(args.filename)

Hope it helps the next frustrated soul who's trying to create a damn image that isn't of their thumb or a blank wall.

-----
I have code on GitHub