Skip to main content

osaic is a simple python module which let you create mosaics from images by issuing a simple python -mosaic foo.jpg command.

The basic idea is to take as input a set of images: the first is used as background for the final mosaic; the others are indexed by average colors and pated, as tiles, over the final mosaic.

In addition, users are enabled to specify the final size of the mosaic (relative to the size of the initial target image) and the number of tiles to use per side.

Dependencies

The module depends on python PIL library (automatically fetched by the installation script) for all the operations concerning image processing. In addition, to add support for jpegs and pngs images, and to enable the module to display mosaics on screen, please install libjpeg, libpng and libtk as well.

Install

To install osaic, you are enabled to grab it from both the mercurial repository and from the Python Package Index (PyPI). The former is preferred for bleeding-edge users, even tough the latter is not guaranteed to be very stable as well.

Mercurial

From sources:

cd /wherever/you/want
hg clone https://bitbucket.org/iamFIREcracker/osaic
python setup.py install

PyPI

From sources:

cd /path/to/workspace
wget http://pypi.python.org/packages/source/o/osaic/osaic-2.0.0.tar.gz
tar zxvf osaic-2.0.0.tar.gz
cd osaic-2.0.0
python setup.py install

From the PyPI:

pip install osaic

Usage

osaic is a module that can be used both as a standalone application and as a standard python module.

Standalone application

A typical usage of the application is to display a mosaic composition created from a source image:

python -mosaic image.jpg

If you want to save the output to a file instead of showing it:

python -mosaic image.jpg -o mosaic-image.jpg

Finally, if you want to create a mosaic which is 4 times bigger than the original image, and with 100 tiles per side, just issue:

python -mosaic -z4 -t100 image.jpg

For everything else use the help message:

python -mosaic -h

Library

The module is a collection of objects and functions with different capabilities: functions for vectors, color transformations, image objects, image indexes and procedure wrappers.

Regarding operation with vectors, the module implement some basic functions not included in standard Python but useful while working with colors:

>>> dotproduct([1, 2, 3], [4, 5, 6])
70
>>> difference([1, 2, 3], [1, 2, 3])
[0, 0, 0]
>>> squaredistance([1, 2, 3], [0, 0, 0])
30

It is possible to find also a couple of functions wrapping up common colors operations, like computation of the average color of an image and color quantization. The latter is particularly useful while trying to keep the CPU work load at low levels:

>>> average_color('almost-red.png')
(240, 10, 20)
>>> quantize_color((240, 10, 20), levels=2)
(192, 64, 64)

As noted earlier, the module is built on top of the Python PIL library. However, we chose not export such external objects, but rather present to users some wrappers, namely ImageWrapper:

>>> img = Image.open('foo.png')
>>> img.size
(640, 480)
>>> img.reratio(5 / 1)
>>> img.crop((0, 0, 10, 10))
>>> img.size
(10, 10)
>>> img.show()

While creating mosaics, it comes in handy to have to possibility to index a set of images and make it possible to search which of them is the most similar, in terms of average color, to another one. The ImageList object is shipped with the module for this reason:

>>> img_list = ImageList(['1.png', '2.png', '3.png'])
>>> img_list.search((255, 0, 0))
ImageTuple(filename='1.png', color=(255, 0, 0), image=None)

Finally, the module is shipped with a mosaicify function which wraps up all the operations needed to create mosaic, including source images indexing, and search of neighbour images depending on the average color:

>>> import osaic
>>> osaic.mosaificy(
...     target='foo.png',
...     sources=['bar.png', 'asd.png', 'bazinga.png'],
...     tiles=128,
...     zoom=4,
...     output='mosaic.png',
... )

Metadata

Release files for osaic 2.0.0

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

Source distribution (sdist)

Source distribution for osaic 2.0.0
File Size Uploaded Provenance
osaic-2.0.0.tar.gz 12.1 kB Without provenance Details

Built distributions (wheels)

Table of built distributions (wheels) for osaic 2.0.0
File Interpreter ABI Platform
osaic-2.0.0.cygwin-1.7.9-i686-py2.6.exe Details
osaic-2.0.0-py2.7.egg Legacy Egg format - - Details
osaic-2.0.0-py2.6.egg Legacy Egg format - - Details

Total release size: 115.4 kB

Release files / osaic-2.0.0.tar.gz

Download URL osaic-2.0.0.tar.gz
Size 12.1 kB
Tags Source
SHA-256 checksum
How to use checksums
4387f5fa2def78714fc1094d147e9d8f80bdac4d93dab0f367651c57469b2fa4
BLAKE2b-256 checksum
How to use checksums
de5a3f380b6ca7fbbc67e34bacb26397b2560476d2e25f79ebacdfe1425ff1b5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / osaic-2.0.0.cygwin-1.7.9-i686-py2.6.exe

Download URL osaic-2.0.0.cygwin-1.7.9-i686-py2.6.exe
Size 68.8 kB
Tags Source
SHA-256 checksum
How to use checksums
de2fc7aa09b945632593fa1179dd2ecfd624c7a920ed1a60128f748ecf65a2af
BLAKE2b-256 checksum
How to use checksums
4d45a1a6a943fe04d8462608b0fdd142a28ceb88c638aecc2fe805d0704277cf
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / osaic-2.0.0-py2.7.egg

Download URL osaic-2.0.0-py2.7.egg
Size 17.2 kB
Tags Egg
SHA-256 checksum
How to use checksums
cfaebbbb0ab4d0e3e61ddb0fcc45bc16e4c292f6e13fe99f67dfbbdc16ca57bc
BLAKE2b-256 checksum
How to use checksums
e6c8b38aebe28104ca40a3fc2682e2e1e545c849d45b33882e04093f0df5c9ea
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / osaic-2.0.0-py2.6.egg

Download URL osaic-2.0.0-py2.6.egg
Size 17.2 kB
Tags Egg
SHA-256 checksum
How to use checksums
bcc3585d85b6e2b5495b35306667de949229f5ed31ef2f34689b6af4a86001d9
BLAKE2b-256 checksum
How to use checksums
2b24db982b40e65490d1fe020d3c745b40c8f0f9dc637f7a01e2df995167b161
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Security for osaic 2.0.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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