diff --git a/Scripts/Miscellaneous/Merge_Images_Vertically/IMAGE/image1.jpg b/Scripts/Miscellaneous/Merge_Images_Vertically/IMAGE/image1.jpg new file mode 100644 index 000000000..ec86b8d05 Binary files /dev/null and b/Scripts/Miscellaneous/Merge_Images_Vertically/IMAGE/image1.jpg differ diff --git a/Scripts/Miscellaneous/Merge_Images_Vertically/IMAGE/image2.jpg b/Scripts/Miscellaneous/Merge_Images_Vertically/IMAGE/image2.jpg new file mode 100644 index 000000000..77c68b7a1 Binary files /dev/null and b/Scripts/Miscellaneous/Merge_Images_Vertically/IMAGE/image2.jpg differ diff --git a/Scripts/Miscellaneous/Merge_Images_Vertically/README.md b/Scripts/Miscellaneous/Merge_Images_Vertically/README.md new file mode 100644 index 000000000..fafc794fe --- /dev/null +++ b/Scripts/Miscellaneous/Merge_Images_Vertically/README.md @@ -0,0 +1,18 @@ +# Merge Images Vertically +Merge images inside a subfolder vertically using Pillow. +Useful for comics and webtoons. + +### Pre-requisites: +You will need to install python on your machine. You can download python from the python.org and install it. +Run `pip install -r requirements.txt` to install modules used. + +### How to run the script +Run `python merge_images_vertically.py`. +Type in the subfolder name in which the images are saved. + +### Screenshot of the console interaction +![Screenshot](usage.png) + +## *Author Name* + +[João Camelo](https://github.com/jrcamelo) \ No newline at end of file diff --git a/Scripts/Miscellaneous/Merge_Images_Vertically/merge_images_vertically.py b/Scripts/Miscellaneous/Merge_Images_Vertically/merge_images_vertically.py new file mode 100644 index 000000000..f94e6fb1f --- /dev/null +++ b/Scripts/Miscellaneous/Merge_Images_Vertically/merge_images_vertically.py @@ -0,0 +1,44 @@ +import numpy as np +import PIL +from PIL import Image +import os +from os import listdir +from os.path import isfile, join + +def merge_pics_vertically(images_list, name): + # Opens all files and stores them in a list + imgs = [Image.open(i) for i in images_list] + min_img_width = min(i.width for i in imgs) + + # Sums up the total height + total_height = 0 + for i, img in enumerate(imgs): + if img.width > min_img_width: + imgs[i] = img.resize((min_img_width, int(img.height / img.width * min_img_width)), Image.ANTIALIAS) + total_height += imgs[i].height + + # Pastes all of them together + img_merge = Image.new(imgs[0].mode, (min_img_width, total_height)) + y = 0 + for img in imgs: + img_merge.paste(img, (0, y)) + y += img.height + + # Then saves the final image + img_merge.save(name + '.jpg') + +def get_files(directory, ext = None): + if ext is None: + ext = [".jpg"] + files = [] + # Scans the folder and gets all files with the extension + for f in os.scandir(directory): + if f.is_file(): + if os.path.splitext(f.name)[1].lower() in ext: + files.append(f.path) + return files + +name = input("Sub-folder with images to be merged: ") +path = os.getcwd() + "/" + name +pictures = get_files(path) +merge_pics_vertically(pictures, path) diff --git a/Scripts/Miscellaneous/Merge_Images_Vertically/requirements.txt b/Scripts/Miscellaneous/Merge_Images_Vertically/requirements.txt new file mode 100644 index 000000000..ea8085281 --- /dev/null +++ b/Scripts/Miscellaneous/Merge_Images_Vertically/requirements.txt @@ -0,0 +1,2 @@ +numpy==1.19.1 +Pillow==7.2.0 \ No newline at end of file diff --git a/Scripts/Miscellaneous/Merge_Images_Vertically/usage.png b/Scripts/Miscellaneous/Merge_Images_Vertically/usage.png new file mode 100644 index 000000000..c28ea9868 Binary files /dev/null and b/Scripts/Miscellaneous/Merge_Images_Vertically/usage.png differ