Skip to main content

image-merger

A small Python library to merge images easily

Installation

pip install image-merger

Usage

Simple use case

from ImageMerger import Merger, ImageToMerge, MERGE_GRID

# Initialize list of images
list_images = [
	ImageToMerge(path='images/samples/1.png'),
	ImageToMerge(path='images/samples/2.png'),
	ImageToMerge(path='images/samples/3.png'),
	ImageToMerge(path='images/samples/4.png')
]

# Load merger with different settings
m = Merger(list_images=list_images)

# Save merged image
m.save_image(filename="images/results/output_4_grid.png")

output_4_grid.png

Parameters

  • limit_horizontal: int: Optional int to define the maximum number of images to append horizontally
  • limit_vertical: int: Optional int to define the maximum number of images to append vertically
  • suffle: bool: Optional boolean to decide if list_images must be shuffled prior to process. Default False
  • merge_strategy: int: Optional int to set the merging strategy. Either MERGE_HORIZONTALLY, - MERGE_VERTICALLY or MERGE_GRID(default)
  • preserve_aspect_ratio: bool: Optional boolean that defines if proportion of each image should be kept or if image can be squeezed/extended to fit. Default False
    • Setting it to True can lead to images being distored to fit layout but there will be no gaps.
    • Setting it to False will kept each image aspect ratio but can lead to black gaps in output image.

Configuration examples

  • ImageToMerge.path can either be a path(local or relative) or HTTP(S) URL
  • limit_horizontal and limit_vertical are optional and can also be used at the same time
  • If limit_horizontal and limit_vertical are not set, and merge_strategy is set to MERGE_GRID The process will try to fit as best as possible all images in a square grid.
  • List of images can be shuffled randomly using shuffle=True parameter

More examples

from ImageMerger import Merger, ImageToMerge

# Initialize list of images
list_images = [
	ImageToMerge(path='images/samples/1.png'),
	ImageToMerge(path='images/samples/2.png'),
	ImageToMerge(path='https://raw.githubusercontent.com/ggouzi/image-merger/main/images/samples/3.png'),
	ImageToMerge(path='https://raw.githubusercontent.com/ggouzi/image-merger/main/images/samples/4.png'),
	ImageToMerge(path='https://raw.githubusercontent.com/ggouzi/image-merger/main/images/samples/5.png')
]

# Load merger with different settings
m = Merger(
    list_images=list_images,
    preserve_aspect_ratio=True,
    limit_vertical=2
  )

# Save merged image
m.save_image(filename="images/results/output_5_grid_keep_aspect_ratio.png")

output_5_grid_keep_aspect_ratio.png

from ImageMerger import Merger, ImageToMerge

# Initialize list of images
list_images = [ImageToMerge(path=f"images/samples/{i}.png") for i in range(1, 11)]

# Load merger with different settings
m = Merger(
    list_images=list_images,
    limit_horizontal=2
)

# Save merged image
m.save_image(filename="images/results/output_10_2rows.png")

output_10_2rows.png

from ImageMerger import Merger, ImageToMerge

# Initialize list of images
list_images = [ImageToMerge(path=f"images/samples/{i}.png") for i in range(1, 11)]

# Load merger with different settings
m = Merger(
    list_images=list_images,
    shuffle=True
)

# Save merged image
m.save_image(filename="images/results/output_10_grid_shuffled.png")

output_10_grid_shuffled.png

References

Release files for image-merger 0.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for image-merger 0.2
File Size Uploaded
image-merger-0.2.tar.gz 7.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for image-merger 0.2
File Interpreter ABI Platform
image_merger-0.2-py3-none-any.whl Python 3 none any Details

Total release size: 17.7 kB

Release files / image-merger-0.2.tar.gz

Download URL image-merger-0.2.tar.gz
Size 7.3 kB
Tags Source
SHA-256 checksum
How to use checksums
04b2f6dc2ed139356ae609bc5f9258a512c4aaa3e9fff00709b06f4b67162032
BLAKE2b-256 checksum
How to use checksums
a588bb36288d5d0eebad39a608ecbcea8f7b99a993ac89144dca08867a5051db
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.10.4

Release files / image_merger-0.2-py3-none-any.whl

Download URL image_merger-0.2-py3-none-any.whl
Size 10.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
25d7b7b5fdd140c62c328ed0ce0008c187d75eb8ed81443557c454711c4d4819
BLAKE2b-256 checksum
How to use checksums
489f12d25e894aeed4afbdf04761361d3f85dd8f9f9be8fca16d3fadb9d9c408
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.10.4

Release history Release notifications | RSS feed

This release

0.2 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page