Answer the question
In order to leave comments, you need to log in
How to split a photo every n pixels?
Let's say I have 3 photos 30'000 pixels high. I'll combine them (I don't know, I'll search later) and get a photo of 90'000 pixels. Next, I need to divide this photo into equal parts, say 2'000 pixels each.
Question: how to divide the above image into equal (2'000 pixels) parts?
I saw the Pil library, but I can't figure out how to use it for something like this. It may also be that in the last piece of the picture there will be less than 2K pixels, it would be better to leave it here.
You need to save in a folder with the numbering "001", "002" and TD. But it's not that important. I 'll figure it out myself there, the main thing is to understand how to share ...
I hope for your help. Thank you.
Answer the question
In order to leave comments, you need to log in
def crop_img(path):
im = add_imgs(path)
size_max = 1800
width, height = im.size
number = 1
while height>size_max:
save = im.crop((0, 0, width, size_max))
save.save(f"D:\\\{'{:03}'.format(number)}.jpg")
im = im.crop((0, size_max, width, height))
height -= size_max
print(number, height)
number += 1
print(number)
im = im.crop((0, 0, width, height))
im.save(f"D:\\\{'{:03}'.format(number)}.jpg")
In a simple version, a picture is a list of 100 lists of 100 cells, each cell of the nested list contains three numbers of the int8 type, reflecting the brightness in one of the three colors (red green blue). Blinding three images with the same width is just connecting three top-level lists.
Then we chop it with banal slices with a step (70 lines, approximately 3 * 70 * 100 = 2100 pixels, and we get a set of required pieces.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question