Create a dummy image with Python + PIL.

With Python + PIL, I created a script that creates a dummy image (called a wireframe image) used for the layout of a web page at once.

Defeated flavor. Python is using 2.7.

image-wire-frame-box.py


#!/usr/bin/env python
# -*- coding: utf-8 -*-
'''
Create a wireframe image
'''

import Image
import ImageDraw
import ImageFont
import sys


def make_image(screen, prefix, extension, pen_color, bg_color):
    """
Create image file
    """

    #The font path is different for each flat form, so take that into consideration (actually, defeat it)
    if sys.platform == "darwin":
        #For OSX
        #Japanese fonts didn't work
        #FONTPATH = '/Library/Fonts/Osaka.ttf'
        FONTPATH = '/Library/Fonts/Verdana.ttf'
    elif sys.platform == "linux2":
        #For Linux
        FONTPATH = '/usr/share/fonts/truetype/fonts-japanese-gothic.ttf'
    else:
        #Other than that, it is judged as Windows (defeat)
        # FONTPATH = 'hgrme.ttc'
        FONTPATH = 'C:\WINDOWS\Fonts\MSGOTHIC.ttc'

    #Specify font
    font = ImageFont.truetype(FONTPATH, 24, encoding='utf-8')

    img = Image.new('RGB', screen, bg_color)
    x, y = img.size
    u = x - 1
    v = y - 1
    draw = ImageDraw.Draw(img)

    draw.line((0, 0, u, 0), pen_color)
    draw.line((0, 0, u, v), pen_color)
    draw.line((0, 0, 0, v), pen_color)
    draw.line((u, 0, 0, v), pen_color)
    draw.line((u, 0, u, v), pen_color)
    draw.line((0, v, u, v), pen_color)

    #Put text in the image (defeat)
    if x > 63 and y > 24:
        draw.text((2, (y - 24) / 2), str(x) + "x" + str(y),
            font=font, fill=pen_color)

    savefile = prefix + str(x) + "x" + str(y) + extension
    img.save(savefile)

if __name__ == '__main__':
    #Image size
    screens = (
        (16, 16),      # favicon
        (32, 32),      # favicon
        (24, 24),      # windows icon
        (48, 48),      # windows icon / avatar
        (96, 96),      # windows icon / avatar
        (64, 64),      # mac icon / avatar
        (128, 128),    # mac icon / avatar
        (100, 100),    # icon / avatar
        (150, 150),    # icon / avatar
        (256, 256),    # icon / avatar ----
        (320, 240),    # QVGA
        (240, 320),    # QVGA
        (640, 480),    # VGA
        (480, 640),    #VGA (vertical)
        (800, 600),    # SVGA
        (600, 800),    #SVGA (vertical)
        (1024, 768),   # XGA
        (768, 1024),   #XGA (vertical)
        (1280, 960),   # Quad-VGA
        (960, 1280),   # Quad-VGA (vertical)
        (1600, 1200),  # UXGA
        (1200, 1600),  #UXGA (vertical)
        (1280, 720),   # HDTV 720p
        (720, 1280),   #HDTV 720p (vertical)
        (1920, 1080),  # HDTV 1080p
        (1080, 1920),  #HDTV 1080p (vertical)----
        (88, 31),      #IMU Micro Bar Micro Bar
        (120, 60),     #IMU Button 2 Button 2
        (160, 600),    #IMU Wide Skyscraper Wide Skyscraper
        (300, 600),    #IMU Half Page Ad Half Page
        (180, 150),    #IMU Rectangle Rectangle (Small)
        (300, 250),    #IMU Medium Rectangle Rectangle (Middle)
        (728, 90),     #IMU Leaderboard Big Banner
        (120, 90),     #IMU (Delete) Button 1 Button 1
        (120, 240),    #IMU (Deleted) Vertical Banner Vertical banner
        (120, 600),    #IMU (Deleted) Skyscraper Skyscraper
        (125, 125),    #IMU (Deleted) Square Button Square button, button
        (234, 60),     #IMU (Deleted) Half Banner Half Banner
        (240, 400),    #IMU (Deleted) Vertical Rectangle Vertical Rectangle
        (250, 250),    #IMU (Deleted) Square Pop-Up Square
        (300, 100),    #IMU (deleted) 3:1 Rectangle 3:1 rectangle
        (336, 280),    #IMU (Deleted) Large Rectangle Large Rectangle, Rectangle (Large)
        (468, 60),     #IMU (Deleted) Full Banner Banner, Full Banner
        (720, 300),    #IMU (Deleted) Pop-Under pop under
        (200, 200),    #Google Square (Small)
        (970, 90),     #Google Large Big Banner, Big Banner (Large)
        (320, 50),     #Google Mobile Big Banner
        (320, 100),    #Google Mobile Banner (Large)
        (240, 400),    #Google "Rectangle (vertical)" Russia
        (980, 120),    #Google "Panorama" Sweden and Finland
        (250, 360),    #Google "Triple Wide Screen" Sweden
        (930, 180),    #Google "Top Banner" Denmark
        (580, 400),    #Google "Netboard" Norway
        (750, 100),    #Google "Billboard" Poland
        (750, 200),    #Google "Double Billboard" Poland
        (750, 300),    #Google "Triple Billboard" Poland
        (170, 40),     #banner Details unknown
        (180, 70),     #banner Details unknown
        (200, 40),     #banner Even the banner size that is often found in Japanese CG
        (400, 40)      #banner Even the banner size that is common in Japan
        )

    #Specify the prefix
    prefix = "wf-"

    #Specify the file extension
    #extension = ".png "
    extension = ".jpg "

    #Specify the drawing color (RGB)
    pen_color = (0x00, 0x00, 0xdd)

    #Specify the background color (RGB) of the image
    bg_color = (0xdd, 0xdd, 0xdd)

    for screen in screens:
        print "size: %d,%d" % (screen[0], screen[1])
        make_image(screen, prefix, extension, pen_color, bg_color)
#EOF

↓ An image like this is created softly. wf-300x600.jpg

Recommended Posts

Create a dummy image with Python + PIL.
Create a directory with python
Create a virtual environment with Python!
Create a Python function decorator with Class
Build a blockchain with Python ① Create a class
[Python] Create a virtual environment with Anaconda
Let's create a free group with Python
Create a word frequency counter with Python 3.4
Create a Python module
Image processing with Python
Create a Python environment
Image Processing with PIL
Create a frame with transparent background with tkinter [Python]
Create polka dot wallpaper with Python Image Library
Create a LINE BOT with Minette for Python
Create a virtual environment with conda in Python
Create a page that loads infinitely with python
[Note] Create a one-line timezone class with python
You can easily create a GUI with Python
Create a python3 build environment with Sublime Text3
Create a color bar with Python + Qt (PySide)
Create an image with characters in python (Japanese)
Steps to create a Twitter bot with python
Create a decision tree from 0 with Python (1. Overview)
Create a new page in confluence with Python
Create a color-specified widget with Python + Qt (PySide)
Create a Photoshop format file (.psd) with python
Create a Python console application easily with Click
Image processing with Python (Part 2)
Create a Wox plugin (Python)
Image processing with PIL (Pillow)
Create a function in Python
Create a dictionary in Python
Image editing with python OpenCV
Create 3d gif with python3
Create an image file using PIL (Python Imaging Library).
[Python] Create a ValueObject with a complete constructor using dataclasses
Create a homepage with django
Why not create a stylish table easily with Python?
Create a python development environment with vagrant + ansible + fabric
Sorting image files with Python (2)
Sorting image files with Python (3)
Create Image Viewer with Tkinter
Image processing with Python (Part 1)
Tweet with image in Python
Sorting image files with Python
Create a python numpy array
Create a dummy data file
Make a fortune with Python
Image processing with Python (Part 3)
Create a Layer for AWS Lambda Python with Docker
Create a heatmap with pyqtgraph
[python] Create a date array with arbitrary increments with np.arange
Create miscellaneous Photoshop videos with Python + OpenCV ② Create still image Photoshop
[Python] How to create a 2D histogram with Matplotlib
[Python] Create a Tkinter program distribution file with cx_Freeze
Create a fake Minecraft server in Python with Quarry
Create a company name extractor with python using JCLdic
Create a 2d CAD file ".dxf" with python [ezdxf]
[Python] Image processing with scikit-image
Create a High Dynamic Range Image (HDR) with OpenCV and Python (Mertens, Robertson, Debevec)