Created
August 8, 2013 16:36
-
-
Save rodriamaro/6186280 to your computer and use it in GitHub Desktop.
random images script generator use: ./random_images.py N_IMAGES
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/python | |
import urllib | |
from random import choice, randrange | |
import os | |
import argparse | |
import sys | |
DEFAULT = 20 | |
if len(sys.argv) > 1: | |
nimages = sys.argv[1] | |
else: | |
nimages = DEFAULT | |
try: | |
nimages = int(nimages) | |
except: | |
nimages = DEFAULT | |
image_sizes = [ 'medrect', 'sqrpop', 'vertrec', 'lrgrec', 'rec', 'pop', 'fullban', 'halfban', 'mibar', 'but1', 'but2', 'vertban', 'sqrbut', 'leadbrd', 'wiskyscrpr', 'skyscrpr', 'hpge'] | |
random_name = os.urandom(16).encode('hex') | |
def make_random_image(size, bg_color, fg_color, text, format="png"): | |
image_url = "http://dummyimage.com/%s/%s/%s&text=%s.%s" % (size, bg_color, fg_color, text,format) | |
filename = random_name+"/"+text+"."+format | |
urllib.urlretrieve(image_url, filename) | |
os.mkdir(random_name) | |
for x in range(0,nimages): | |
random_color_1 = "".join([hex(randrange(0, 255))[2:] for i in range(3)]) | |
random_color_2 = "".join([hex(randrange(0, 255))[2:] for i in range(3)]) | |
size = choice(image_sizes); | |
filename = "image%d" % (x) | |
make_random_image(size, random_color_1, random_color_2, filename); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment