Advertisement
Hellerick_Ferlibay

Image_concatenator.py

Jul 5th, 2020
1,058
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.54 KB | None | 0 0
  1. import os
  2. from PIL import Image
  3.  
  4. def concat_folder(folder_path):
  5.     print('Folder:', folder_path)
  6.     file_paths = []
  7.     for folder,subfolders,files in os.walk(folder_path):
  8.         for f in files:
  9.             file_paths = file_paths + [os.path.join(folder,f)]
  10.     file_paths.sort(
  11.         key = lambda f: os.path.getsize(f),
  12.         reverse = True)
  13.     file_paths = sorted([f for f in file_paths if f.lower().endswith(('.png','.jpeg','.jpg','.gif', '.webp'))])
  14.     images = [Image.open(fp) for fp in file_paths]
  15.     output_size = (
  16.         max([i.width for i in images]),
  17.         sum([i.height for i in images]),
  18.         )
  19.     print('output_size:', output_size)
  20.     output_image = Image.new('RGB', output_size)
  21.     output_image_path = os.path.join(folder_path)+'.png'
  22.     print('output_image_path:', output_image_path)
  23.     y = 0
  24.     for i in images:
  25.         output_image.paste(i, (0,y))
  26.         y = y + i.height
  27.     output_image.save(output_image_path)
  28.  
  29.  
  30. paths = '''
  31. /home/hellerick/Documents/Akiba/Manga/Q/TF. Gisou Furin/Ch 01
  32. /home/hellerick/Documents/Akiba/Manga/Q/TF. Gisou Furin/Ch 02
  33. /home/hellerick/Documents/Akiba/Manga/Q/TF. Gisou Furin/Ch 03
  34. /home/hellerick/Documents/Akiba/Manga/Q/TF. Gisou Furin/Ch 04
  35. /home/hellerick/Documents/Akiba/Manga/Q/TF. Gisou Furin/Ch 05
  36. /home/hellerick/Documents/Akiba/Manga/Q/TF. Gisou Furin/Ch 06
  37. /home/hellerick/Documents/Akiba/Manga/Q/TF. Gisou Furin/Ch 07
  38. /home/hellerick/Documents/Akiba/Manga/Q/TF. Gisou Furin/Ch 08
  39. /home/hellerick/Documents/Akiba/Manga/Q/TF. Gisou Furin/Ch 09
  40. /home/hellerick/Documents/Akiba/Manga/Q/TF. Gisou Furin/Ch 10
  41. /home/hellerick/Documents/Akiba/Manga/Q/TF. Gisou Furin/Ch 11
  42. /home/hellerick/Documents/Akiba/Manga/Q/TF. Gisou Furin/Ch 12
  43. /home/hellerick/Documents/Akiba/Manga/Q/TF. Gisou Furin/Ch 13
  44. /home/hellerick/Documents/Akiba/Manga/Q/TF. Gisou Furin/Ch 14
  45. /home/hellerick/Documents/Akiba/Manga/Q/TF. Gisou Furin/Ch 15
  46. /home/hellerick/Documents/Akiba/Manga/Q/TF. Gisou Furin/Ch 16
  47. /home/hellerick/Documents/Akiba/Manga/Q/TF. Gisou Furin/Ch 17
  48. /home/hellerick/Documents/Akiba/Manga/Q/TF. Gisou Furin/Ch 18
  49. /home/hellerick/Documents/Akiba/Manga/Q/TF. Gisou Furin/Ch 19
  50. /home/hellerick/Documents/Akiba/Manga/Q/TF. Gisou Furin/Ch 20
  51. /home/hellerick/Documents/Akiba/Manga/Q/TF. Gisou Furin/Ch 21
  52. /home/hellerick/Documents/Akiba/Manga/Q/TF. Gisou Furin/Ch 22
  53. /home/hellerick/Documents/Akiba/Manga/Q/TF. Gisou Furin/Ch 23
  54. '''
  55.  
  56.  
  57. if __name__ == '__main__':
  58.     paths = [p for p in paths.split('\n') if p!='']
  59.     print(paths)
  60.     for p in paths:
  61.         concat_folder(p)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement