split-image is a Python package that you can use from the command line to split an image into tiles.
pip install split-image
From the command line:
split-image [-h] [-s] image_path rows cols
As a regular module import:
from split_image import split_image
split_image(image_path, rows, cols, should_square, should_cleanup, [output_dir])
# e.g. split_image("bridge.jpg", 2, 2, True, False)split-image cat.png 2 2
This splits the cat.png image in 4 tiles (2 rows and 2 columns).
split-image bridge.png 3 4 -s
This splits the bridge.png image in 12 tiles (3 rows and 4 columns). The -square arguments resizes the image into a square before splitting it. The background color used to fill the square is determined from the image automatically.
split-image cat.jpg 2 2 -r
Will attempt to merge similarly named image tiles to one image. So, if you have these images in the current directory:
- cat_0.jpg
- cat_1.jpg
- cat_2.jpg
- cat_3.jpg
they will be merged according to their file name:
split-image image_dir 4 2
Will split all images contained in the image_dir folder.
split-image test.jpg 4 2 --cleanup
Will delete the original image after the process.
split-image test.jpg 4 2 --load-large-images
When working with large images (over 178,956,970 pixels), you may get an error. Pass this flag to override this.
split-image test.jpg 2 2 --output-dir <dir-name>
Set the output directory for image tiles (e.g. 'outp/images'). Defaults to the current working directory.
split-image test.jpg 3 4 --quiet
Will suppress all log messages (except errors and warnings) when running.
positional arguments:
  image_path    The path to the image or directory with images to split.
  rows          How many rows to split the image into (horizontal split).
  cols          How many columns to split the image into (vertical split).
optional arguments:
  -h, --help                Show this help message and exit
  -s, --square              If the image should be resized into a square before splitting.
  -r, --reverse             Reverse the splitting process, i.e. merge multiple tiles of an image into one.
  --cleanup                 After splitting or merging, delete the original image/images.
  --load-large-images       Pass this flag for use with really large images.
  --output-dir <dir-name>   Set the output directory for image tiles (e.g. 'outp/images'). 
  --quiet                   Run without printing any messages.
Cat photo by Manja Vitolic on Unsplash
Bridge photo by Lance Asper on Unsplash




