Created
June 9, 2015 03:14
-
-
Save bcattle/3db0d9afd4a1494ac5d2 to your computer and use it in GitHub Desktop.
Script that generates solid-color test images for when RGBA should really be BGRA...
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/env python | |
""" | |
draw-color-test-image.py | |
Bryan Cattle | |
Draws a solid color test image using the supplied parameters | |
""" | |
import click | |
from PIL import Image | |
@click.command() | |
@click.option('--format', default='PNG', help='Format to save the image file in, e.g. "PNG"') | |
@click.option('--color', default='red', help='Color to fill the output image with, e.g. "red"') | |
@click.option('--size', default='480x640', help='Size of the output image to generate, e.g. "480x640"') | |
@click.option('--save/--no-save', default=True, help='Save the image, True by default') | |
@click.option('--preview/--no-preview', default=False, help='Show a preview of the saved image') | |
def generate_test_image(format, color, size, save, preview): | |
""" | |
Generates a test pan image of the specifed size, having a grid of a certain aspect ratio | |
EXAMPLES:\n | |
./draw-photopan-test-image.py --preview\n | |
./draw-photopan-test-image.py --size 3264x2448 --preview | |
""" | |
# Size is expected to be a string like "640x480" | |
a, b = size.split("x") | |
img_width = int(a) | |
img_height = int(b) | |
# im = Image.new('RGB', (img_width, img_height), (255, 255, 255, 0)) | |
im = Image.new('RGB', (img_width, img_height), color) | |
if save: | |
im.save('test-color-image-%s-%d.%s' % (color, img_width, format.lower()), format.upper()) | |
if preview or not save: | |
im.show() | |
if __name__ == '__main__': | |
generate_test_image() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment