Advertisement
xah

webtoon stitch v0.0.0

xah
Mar 3rd, 2017 (edited)
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.10 KB | None | 0 0
  1. #Adapted from https://gist.github.com/jweir/7ce4eb2ac5f7c9b8fe015fe4278a6800
  2. #Intended for webtoon scanlators who use PNG format.
  3.  
  4. from PIL import Image
  5. import os
  6.  
  7. # change this to the director that has your images
  8. dir = input('Input the directory.')
  9. out_file = "joined-images.png"
  10.  
  11. def getFiles(dir):
  12.     files = []
  13.     for c in os.listdir(dir):
  14.         _, ext = os.path.splitext(c)
  15.  
  16.         if ext == '.png':
  17.             files.append(c)
  18.  
  19.     return files
  20.  
  21. def merge_images(dir, file):
  22.     image = Image.open(os.path.join(dir, file))
  23.     base = Image.open(out_file)
  24.  
  25.     (width1, height1) = image.size
  26.     (width2, height2) = base.size
  27.  
  28.     result_width = max(width1, width2)
  29.     result_height = height1 + height2
  30.  
  31.     out = Image.new('RGB', (result_width, result_height))
  32.     out.paste(im=base, box=(0, 0))
  33.     out.paste(im=image, box=(0, height2))
  34.  
  35.     out.save(out_file,"PNG")
  36.     return out
  37.  
  38. def createTarget():
  39.     result = Image.new('RGB', (1, 1))
  40.     result.save(out_file,"PNG")
  41.  
  42.  
  43.  
  44. ff = getFiles(dir)
  45. createTarget()
  46. for f in ff:
  47.     merge_images(dir, f)
  48.  
  49. print("All done.")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement