Skip to content

Repository files navigation

Image Composition Engine

Image compositor based on Node.js + Moleculer + Sharp

What it does

This software combines multiple image layers (like Photoshop layers) to create unique compositions. Each layer is stacked on top of another, creating final images with transparency.

Result Examples

Here are some examples of images generated by the system:

Connected Star - 0001

Connected Star - 0195

Connected Star - 0362

How it works

1. Image Layers (Assets)

Images are organized in numbered folders (assets/0/, assets/1/, assets/2/, etc.). Each folder represents a layer:

  • assets/0/ - Background (base image)
  • assets/1/ - First layer on top
  • assets/2/ - Second layer on top
  • And so on...

Important: All images must have transparency (PNG) for the overlay to work correctly. The software combines any image with transparency, enabling endless creation possibilities.

2. Combination System

The readAssets scans all folders and creates all possible combinations in the database. Each combination is unique and non-repeating.

3. Numbers

Numbers are automatically generated from PNG fonts (in the fonts/ folder). Each digit (0-9) is a separate image, and the software automatically composes the numbers.

You can use your own fonts by placing PNG images of 0-9 in the fonts/ folder.

4. Resolution

  • Current images: 10000 x 10000 px (10K)
  • High resolution: The software can handle large resolution images
  • Note: With lower resolutions, processing time is significantly faster

5. Image Format

Images don't need to be square, but it is recommended that all layers have the same resolution. Otherwise, the final image may have unexpected behavior (images out of position, cropped, etc.).

6. Rescale

The rescale action scales images to a percentage of their original size. It works with both:

  • Folder structure: Will maintain the folder hierarchy (e.g., assets/0/output/0/)
  • Single folder: Will process all PNG files directly

Parameters:

  • sourceDir: Source folder path
  • outputDir: Destination folder path
  • percentage: Scale percentage (e.g., 50 = 50% of original, 200 = double size)

Examples:

  • percentage: 100 → keeps original size
  • percentage: 50 → reduces to half
  • percentage: 200 → doubles the size

Use case: If your assets are 10K (10000x10000), processing is slow. Scale to 40% for much faster generation, then use the smaller images for testing or quick previews.

Install

npm install

REPL Mode (interactive terminal)

npm run dev

Quick Commands

# Populate database with combinations
mol $ call imagery.readAssets

# Create images without numbers
mol $ call imagery.createImage '{"count": 1}'

# Create images with numbers
mol $ call imagery.createImageWithNumbers '{"count": 1}'

# Rescale images (e.g., 50% of original size)
mol $ call imagery.rescale '{"sourceDir": "./assets/", "outputDir": "./dist/output-scale/", "percentage": 50}'

Structure

image-composition-engine/
├── assets/           # Original images (layers)
│   ├── 0/           # Backgrounds
│   ├── 1/           # Letters
│   ├── 2/           # Shapes
│   ├── 3/           # Effects
│   ├── 4/           # Magic
│   └── 5/           # Glow
├── fonts/            # Numbers (0-9) - you can replace with your own fonts
├── demo-material/    # Generated image examples
├── dist/
│   ├── data/        # SQLite database
│   ├── numbers/     # Generated numbers
│   └── output/      # Final images

Customization

To create your own compositions:

  1. Place your PNG images with transparency in folders assets/0/, assets/1/, etc.
  2. Run readAssets to generate combinations
  3. Use createImageWithNumbers to generate your images

Tests

node test/engine.test.js

About

No description, website, or topics provided.

Resources

Stars

2 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages