Last active
February 15, 2020 03:18
-
-
Save Themis3000/39c679f6413767217c216f7e9c6e55b0 to your computer and use it in GitHub Desktop.
recursively cuts images all images in a file into equal squares according to settings, orginally used to cut out the cards against humanity printable pages into individual images. Great for turning printable cardgame images into individual card 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
from PIL import Image | |
import os | |
left_margin = 2 | |
top_margin = 2 | |
width = 165 | |
height = 236 | |
right_padding = 4 | |
bottom_patting = 4 | |
directory = r'uno' | |
cards_height = 6 | |
cards_width = 10 | |
for file in os.listdir(directory): | |
image = Image.open(f'{directory}/{file}') | |
for column in range(cards_height): | |
for row in range(cards_width): | |
cropped = image.crop((left_margin + (width * row), | |
top_margin + (height * column), | |
left_margin + (width * (row + 1)) - right_padding, | |
top_margin + (height * (column + 1)) - bottom_patting)) | |
cropped.save(f'images_output/{str(row)},{str(column)} - {file}') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment