Skip to content

Instantly share code, notes, and snippets.

@sparkstar
Last active January 16, 2023 19:19
Show Gist options
  • Save sparkstar/c6bff470e84912566113 to your computer and use it in GitHub Desktop.
Save sparkstar/c6bff470e84912566113 to your computer and use it in GitHub Desktop.
[python] random image generator
"""
20180828 code fixed
$ pip freeze
numpy==1.15.1
Pillow==5.2.0
pkg-resources==0.0.0
"""
#!/usr/bin/env python
import os
import time
import numpy
from PIL import Image
def create_image(width = 1920, height = 1080, num_of_images = 100):
width = int(width)
height = int(height)
num_of_images = int(num_of_images)
current = time.strftime("%Y%m%d%H%M%S")
os.mkdir(current)
for n in range(num_of_images):
filename = '{0}/{0}_{1:03d}.jpg'.format(current, n)
rgb_array = numpy.random.rand(height,width,3) * 255
image = Image.fromarray(rgb_array.astype('uint8')).convert('RGB')
image.save(filename)
def main(args):
create_image(width = args[0], height = args[1], num_of_images = args[2])
return 0
if __name__ == '__main__':
import sys
status = main(sys.argv[1:])
sys.exit(status)
@i-am-programmer-9
Copy link

What the type of Images files are downloading
I wrote in CMD python taking_random_image.py 1280 720 4 to call it
20200927122402_002

20200927122402_000

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment