Last active
September 24, 2021 01:37
-
-
Save ChewRafa/3b54207abd23b37b9d8dd3d5e7d94ccb to your computer and use it in GitHub Desktop.
Este programa permite cortar imagenes por lotes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python3 | |
from PIL import Image | |
import glob, os, os.path | |
def preparar_paginas(is_even): | |
#numero de archivos en la carpeta | |
files_count = len(os.listdir('01_rename/')) | |
print('Hay un total de ' + str(files_count) + ' archivos en la carpeta.') | |
#carpeta origen | |
path_orig = '01_rename/' | |
#carpeta destino | |
path_crops = '02_crops/' | |
contador = 0 | |
for original in glob.glob( path_orig + '*.jpg'): | |
file, ext = os.path.splitext(original) | |
print("Leyendo :" + original) | |
splitted = os.path.split(file) | |
im = Image.open(original) | |
if is_even: | |
#right 1 | |
x_start = 261 | |
y_start = 42 | |
x_end = x_start + 690 | |
y_end = y_start + 863 | |
outfile = os.path.join(path_crops,'crop_right_'+ splitted[1] + '.png') | |
# outfile = os.path.join(path_crops,contador+ '.png') | |
contador+1 | |
else: | |
#left 1 | |
x_start = 951 | |
y_start = 42 | |
x_end = x_start + 690 | |
y_end = y_start + 863 | |
outfile = os.path.join(path_crops,'crop_left_'+ splitted[1] + '.png') | |
# outfile = os.path.join(path_crops,contador+ '.png') | |
contador+1 | |
print("Guardado como " + outfile) | |
region = im.crop((x_start , y_start , x_end , y_end)) | |
region.save(outfile , "PNG") | |
print(outfile) | |
preparar_paginas(True) | |
preparar_paginas(False) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment