Image Slicing with Python

Slicing and manipulating images with a Python GUI program using the Pillow and tkinter GUI packages.

Table of Contents


I recently worked on a CTF challenge with an image that was sliced into chunks and rearranged. The initial image looked like this:


I spent some time overengineering a python script to help me solve other CTF challenges like this in the future. I mostly wasted my time as challenges get very specific and highly customized. That said, the tool is still fun to use and can be found here.

It should operate cross-platform and gives options to slice the image into desired chunks of size WIDTHxHEIGHT, you can then crop each slice, scale them, rotate them, and output into a grid of X columns. You can also dump the slices and run a custom script against them.

script output

Above you see the image has been reconstructed by taking slices of the skewed image, using slices of size 7x100, and rearranging the slices into a single row.

Note that a simple command can be run to convert the image back, instead of using this tool: convert -set colorspace Gray +append +repage -crop 266x100 bleepbloop_sliced.jpg original_image.jpg

The code is sloppy and the functionality can also be slightly buggy as this was just a quick POC; I had no experience with the Pillow or tkinter GUI packages - it was just a fun side project for a few hours. That said, someone else may want to clean up and expand on or just open an image and play with it. Maybe one day it will actually be useful for something, who knows…