Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #Adapted from https://gist.github.com/jweir/7ce4eb2ac5f7c9b8fe015fe4278a6800
- #Intended for webtoon scanlators who use PNG format.
- from PIL import Image
- import os
- # change this to the director that has your images
- dir = input('Input the directory.')
- out_file = "joined-images.png"
- def getFiles(dir):
- files = []
- for c in os.listdir(dir):
- _, ext = os.path.splitext(c)
- if ext == '.png':
- files.append(c)
- return files
- def merge_images(dir, file):
- image = Image.open(os.path.join(dir, file))
- base = Image.open(out_file)
- (width1, height1) = image.size
- (width2, height2) = base.size
- result_width = max(width1, width2)
- result_height = height1 + height2
- out = Image.new('RGB', (result_width, result_height))
- out.paste(im=base, box=(0, 0))
- out.paste(im=image, box=(0, height2))
- out.save(out_file,"PNG")
- return out
- def createTarget():
- result = Image.new('RGB', (1, 1))
- result.save(out_file,"PNG")
- ff = getFiles(dir)
- createTarget()
- for f in ff:
- merge_images(dir, f)
- print("All done.")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement