Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Dec 22, 2023. It is now read-only.

Commit 5b8ab2a

Browse files
Merge pull request #597 from jrcamelo/master
Merge Images Vertically
2 parents 9dcc64a + 1fa3d1a commit 5b8ab2a

File tree

6 files changed

+64
-0
lines changed

6 files changed

+64
-0
lines changed
5.73 KB
Loading[フレーム]
5.93 KB
Loading[フレーム]
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Merge Images Vertically
2+
Merge images inside a subfolder vertically using Pillow.
3+
Useful for comics and webtoons.
4+
5+
### Pre-requisites:
6+
You will need to install python on your machine. You can download python from the python.org and install it.
7+
Run `pip install -r requirements.txt` to install modules used.
8+
9+
### How to run the script
10+
Run `python merge_images_vertically.py`.
11+
Type in the subfolder name in which the images are saved.
12+
13+
### Screenshot of the console interaction
14+
![Screenshot](usage.png)
15+
16+
## *Author Name*
17+
18+
[João Camelo](https://github.com/jrcamelo)
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import numpy as np
2+
import PIL
3+
from PIL import Image
4+
import os
5+
from os import listdir
6+
from os.path import isfile, join
7+
8+
def merge_pics_vertically(images_list, name):
9+
# Opens all files and stores them in a list
10+
imgs = [Image.open(i) for i in images_list]
11+
min_img_width = min(i.width for i in imgs)
12+
13+
# Sums up the total height
14+
total_height = 0
15+
for i, img in enumerate(imgs):
16+
if img.width > min_img_width:
17+
imgs[i] = img.resize((min_img_width, int(img.height / img.width * min_img_width)), Image.ANTIALIAS)
18+
total_height += imgs[i].height
19+
20+
# Pastes all of them together
21+
img_merge = Image.new(imgs[0].mode, (min_img_width, total_height))
22+
y = 0
23+
for img in imgs:
24+
img_merge.paste(img, (0, y))
25+
y += img.height
26+
27+
# Then saves the final image
28+
img_merge.save(name + '.jpg')
29+
30+
def get_files(directory, ext = None):
31+
if ext is None:
32+
ext = [".jpg"]
33+
files = []
34+
# Scans the folder and gets all files with the extension
35+
for f in os.scandir(directory):
36+
if f.is_file():
37+
if os.path.splitext(f.name)[1].lower() in ext:
38+
files.append(f.path)
39+
return files
40+
41+
name = input("Sub-folder with images to be merged: ")
42+
path = os.getcwd() + "/" + name
43+
pictures = get_files(path)
44+
merge_pics_vertically(pictures, path)
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
numpy==1.19.1
2+
Pillow==7.2.0
4.92 KB
Loading[フレーム]

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /