Image splitting function