Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import pygame, shutil, os
- path1 = "Input"
- path2 = "Output"
- def transform (p, path1, path2):
- p, path1, path2 = os.path.abspath(p), os.path.abspath(path1), os.path.abspath(path2)
- return p.replace(path1, path2)
- #count the files
- dirfiles = 0
- for directory, dirs, files in os.walk(path1):
- dirfiles += len(files)
- currfiles = 0
- pygame.init()
- per, mod = int(input().strip()), int(input().strip())
- for directory, dirs, files in os.walk(path1):
- #create directory structure in path2
- if not os.path.exists(transform(directory, path1, path2)) :
- os.makedirs (transform(directory, path1, path2))
- for file in files:
- #create file paths
- fromp = os.path.join(directory, file)
- top = transform (fromp, path1, path2)
- #skip already done files, not image files and files belonging to another proccess
- if currfiles % per != mod or os.path.exists(top) or os.path.splitext(fromp)[1].lower() not in [".jpg", ".png"]:
- currfiles += 1
- continue
- #paths have Unicode names, so "pygame.image.load(fromp)" would not work
- img = pygame.image.load(open(fromp, "rb"), fromp)
- x, y = img.get_rect().bottomright
- zoom = max (600/x, 600/y)
- img_new = pygame.transform.smoothscale (img, (round (zoom*x), round(zoom*y)))
- #same here, Unicode paths
- pygame.image.save (img_new, "temp.jpg")
- shutil.copyfile("temp.jpg", top)
- currfiles +=1
- print ("\r{}/ {}".format (currfiles, dirfiles), end="")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement