Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
A python command line tool to create mosaic pics
from PIL import Image
from argparse import ArgumentParser
parser = ArgumentParser()
parser.add_argument('--input', dest='input_file', type=str, required=True)
parser.add_argument('--size', dest='pix_size', type=int, required=True)
parser.add_argument('--output', dest='output_file', type=str, required=True)
args = parser.parse_args()
background_color = (255,)*3
pix_size = args.pix_size
image =
image = image.resize((image.size[0]//pix_size, image.size[1]//pix_size),
image = image.resize((image.size[0]*pix_size, image.size[1]*pix_size),
pixel = image.load()
for i in range(0, image.size[0], pix_size):
for j in range(0, image.size[1], pix_size):
for r in range(pix_size):
pixel[i+r, j] = background_color
pixel[i, j+r] = background_color, 'png')

This comment has been minimized.

Copy link
Owner Author

@nejdetckenobi nejdetckenobi commented Feb 2, 2017


./ --input "/path/to/image.png" --output "/path/to/output.png" --size GRID_CELL_SIZE

Output is always a PNG file.

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