I am trying to make a program that loads and image and then splits it in different parts and saves these differenct parts in a folder. However, instead of saving the cropped image it saves the whole image
import sys, pygame
from pygame import *
pygame.init()
while True:
image=pygame.image.load(raw_input("Enter the file: "))
rows=int(input("Enter the number of rows: "))
columns=int(input("Enter the number of columns: "))
output=raw_input("Enter the output folder: ")
width=image.get_width()/columns
height=image.get_height()/rows
print ("In progress...")
for i in range(0, rows):
for j in range(0, columns):
cropped_image=pygame.transform.chop(image, (j*columns, i*rows, width, height))
cropped_output=output+"/" + str(i)+"_"+str(j)+".png"
pygame.image.save(cropped_image, cropped_output)
print ("completed")
instead of saving cropped_image (only a part of the image) it saves the whole image. Any idea why it dosen’t work?
Thanks
You are chopping into tiles of size
widthxheight. So the origin of the tile on rowiand columnjisj*width,i*height– notj*columns,i*rows.