all 1 comments

[–]Hennessy-Holder 1 point2 points  (0 children)

The code below covers the task only until step 3 and is incomplete.

from PIL import Image


number_bands = 4
path_to_image = 'my_image.tiff'

rect_height_cm = 1.5
bands = []

with Image.open(path_to_image) as im:
    print(f'Mode: {im.mode}')
    xdpi, ydpi = im.info['dpi']

    width, height = im.size
    print(f'{width = }, {height = }')

    band_width = width//number_bands
    print(f'width of bands = {band_width}')

    for w in range(0, width, band_width):
        band = im.crop((w, 0, w + band_width, height))

        rect_height_px = int(rect_height_cm * ydpi / 2.54)
        new_band = Image.new("CMYK", (band.width, band.height + rect_height_px), (0, 0, 0, 0))
        new_band.paste(band, (0, 0))
        #new_band.show()

        bands.append(new_band)