Last active
December 16, 2015 02:18
-
-
Save 2get/5361056 to your computer and use it in GitHub Desktop.
create consecutive image連番画像生成スクリプトPILを使用します。
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 | |
# -*- coding: utf-8 -*- | |
# pip install pillow | |
from PIL import Image | |
from PIL import ImageDraw | |
from PIL import ImageFont | |
WIDTH = 480 | |
HEIGHT = 320 | |
TRUE_TYPE_FONT = '/Library/Fonts/Osaka.ttf' | |
FONT_SIZE = 64 | |
def create_consecutive_image(num): | |
size = len(str(num)) | |
filename_base = '%0' + str(size) + 'd.jpg' | |
for i in range(1, num + 1): | |
filename = filename_base % i | |
background_color = (255, 204, 204) | |
font_color = (50, 50, 50) | |
img = Image.new('RGB', (WIDTH, HEIGHT), background_color) | |
font = ImageFont.truetype(TRUE_TYPE_FONT, FONT_SIZE, encoding='utf-8') | |
draw = ImageDraw.Draw(img) | |
draw.text((50, 50), filename, font=font, fill=font_color) | |
img.save(filename) | |
if __name__ == '__main__': | |
create_consecutive_image(10) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment