from PIL import Image

img = "m-taquin-m.png"
input = """h, 0, 23
v, 7, -10
h, 23, -18
h, 18, 3
h, 0, -19
h, 7, 8
h, 17, -12
v, 7, 4
v, 0, 24
h, 22, 3
v, 8, -15
h, 24, -3
h, 2, 0
h, 11, -2
v, 1, 22
v, 17, -17
v, 2, 11
v, 20, 15
v, 18, -12
h, 1, 18
h, 24, -6
h, 7, -18
v, 8, 5
v, 5, -1
v, 6, 18
v, 22, 19
h, 19, 16
h, 17, 22
h, 5, 5
v, 8, 16
h, 21, -4
h, 7, -22
v, 12, -7
h, 6, 12
v, 6, 17
v, 12, 17
v, 4, -8
h, 7, 23
v, 23, 13
v, 18, 1
v, 7, -16
v, 2, 24
h, 3, -15
h, 21, 3
h, 12, 0
v, 16, -8
h, 21, 22
h, 21, 10
v, 24, 17
v, 3, -6
v, 5, 5
h, 23, 22
v, 16, 24
h, 16, -18
v, 20, 8
h, 4, -1
h, 17, 9
h, 19, -4
v, 0, -17
v, 9, -9
h, 7, 12
h, 2, 22
v, 2, 24
h, 4, 18
v, 17, -14
v, 16, 14
v, 6, 10
h, 22, -5
v, 21, 17
v, 14, 9
v, 3, -9
h, 2, -3
h, 18, 11
h, 18, -10
h, 2, 21
h, 7, -20
h, 10, -20
h, 8, 18
v, 6, 10
h, 23, 12
v, 7, 6
v, 6, -18
h, 21, 3
v, 13, 2
v, 23, -21
h, 1, 1
v, 3, -9
h, 6, 10
v, 4, 3
h, 8, 5
h, 2, 4
h, 1, 17
h, 2, 24
h, 5, 2
v, 15, -11
v, 1, -14
v, 0, 0
v, 14, -6
v, 22, 22
v, 4, -12"""

bandelettes = 25

img = Image.open(img)

width, height = img.size
bandelette_largeur = width//bandelettes

img_h = Image.new(img.mode, (width, bandelette_largeur))
img_v = Image.new(img.mode, (bandelette_largeur, height))

for move in input.split("\n")[::-1]:
    move_type, move_band, move_size = move.replace(" ", "").split(",")
    print(move_type, move_band, move_size)
    move_band = int(move_band)
    move_size = (-int(move_size))%bandelettes

    if move_type == "h":
        region1 = img.crop((width - move_size*bandelette_largeur, move_band*bandelette_largeur, width, (move_band+1)*bandelette_largeur))
        region2 = img.crop((0, move_band*bandelette_largeur, width - move_size*bandelette_largeur, (move_band+1)*bandelette_largeur))

        img.paste(region1, (0, move_band*bandelette_largeur))
        img.paste(region2, (move_size*bandelette_largeur, move_band*bandelette_largeur))
    else:
        region1 = img.crop((move_band*bandelette_largeur, height - move_size*bandelette_largeur, (move_band+1)*bandelette_largeur, height))
        region2 = img.crop((move_band*bandelette_largeur, 0, (move_band+1)*bandelette_largeur, height - move_size*bandelette_largeur))

        img.paste(region1, (move_band*bandelette_largeur, 0))
        img.paste(region2, (move_band*bandelette_largeur, move_size*bandelette_largeur))

img.show()
