Dec-18-2017, 10:28 AM
Hi everyone
I am trying to develop a python script that can crop multiple images from one image and export each crop to a new image. The purpose is to "cut out" pieces for boardgames for future development. I'll try to be very specific as what I need it to do / where I'm at in development.
below is an example of the file I need to crop. I need a script to basically crop each piece, and export that piece to a new png file with a new name. doing this by hand is excruciating, hence why im trying to use python.
![[Image: pic594563_md.jpg]](https://cf.geekdo-images.com/images/pic594563_md.jpg)
now here's where I'm at with my code so far using the PIL library, which allows for image processing. If anyone can help me out with this, it would be super appreciated, I have several paid jobs coming up involving this and would be amazing if I could cut hours out of the development process.
# wargame counter cutter # developed by Ray Weiss # import image class from PIL import Image # command line arguments from sys import argv # bringing in arguments from command line, defines numbers for program filename = argv[1] vert_to_counter = argv[2] horiz_to_counter = argv[3] counter_size = argv[4] counters_in_a_row = argv[5] rows_of_counters = argv[6] columns_of_counters = argv[7] i = 0 # reserving use as iterators r = 0 img = Image.open(filename) new_counters = () new_image_number = 1 while i != (rows_of_counters + 1) and r != (columns_of_counters + 1): new_img = img.crop((vert_to_counter, horiz_to_counter, 72, 72))from here im a little stumped, I figure I have to supply the program several arguments as specified to get it to work, but now I am at a loss as to what to do.
Thanks!
Ray