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 06818c2

Browse files
committed
Merge Images Vertically
1 parent ae9b392 commit 06818c2

File tree

6 files changed

+59
-0
lines changed

6 files changed

+59
-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: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
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+
imgs = [Image.open(i) for i in images_list]
10+
min_img_width = min(i.width for i in imgs)
11+
12+
total_height = 0
13+
for i, img in enumerate(imgs):
14+
if img.width > min_img_width:
15+
imgs[i] = img.resize((min_img_width, int(img.height / img.width * min_img_width)), Image.ANTIALIAS)
16+
total_height += imgs[i].height
17+
18+
img_merge = Image.new(imgs[0].mode, (min_img_width, total_height))
19+
y = 0
20+
for img in imgs:
21+
img_merge.paste(img, (0, y))
22+
y += img.height
23+
img_merge.save(name + '.jpg')
24+
25+
def get_files(directory, ext = [".jpg"]):
26+
files = []
27+
for f in os.scandir(directory):
28+
if f.is_file():
29+
if os.path.splitext(f.name)[1].lower() in ext:
30+
files.append(f.path)
31+
return files
32+
33+
name = input("Sub-folder with images to be merged: ")
34+
path = os.getcwd() + "/" + name
35+
pictures = get_files(path)
36+
merge_pics_vertically(pictures, path)
37+
38+
39+
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 によって変換されたページ (->オリジナル) /