• Stars
    star
    163
  • Rank 231,141 (Top 5 %)
  • Language
    TypeScript
  • License
    MIT License
  • Created over 4 years ago
  • Updated almost 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Create beautiful mosaics from images and photos

photosaic

Create beautiful mosaics of an image from an original you specify, and are made up of many small images/photos you also provide!

Install

$ npm install -s photosaic

Usage

import fs from 'fs'
import Photosaic from 'photosaic'

const mosaic = Photosaic(`./targetImgForMosaic.png`, [
  `./subImg1.png`,
  `./subImg2.png`,
  `./subImg3.png`,
])
const finalMosaicBuffer = await mosaic.build()
await fs.promises.writeFile(`./finalMosaic.png`, finalMosaicBuffer)

Main Image Type

  • type PhotosaicImage = string | Buffer | Readable: main abstraction of an "image" used by Photosaic
    • string: the full file path of the image on the local file system
    • Buffer: a raw buffer of an image
    • Readable: a readable stream of an image to be piped to a writable stream

Constructor

  • Photosaic(sourceImg, subImages, options?): factory function containing functionality to build mosaics
    • sourceImg: PhotosaicImage: The image of the final mosaic that will be created
    • subImages: PhotosaicImage[]: The small, subImages that will be used to build the mosaic
    • options?: additional options you can provide to customize the output mosaic created
      • options.gridNum?: number = 10: The final mosaic will be made up of a gridNum x gridNum grid of subImages
      • options.intensity?: number = 0.5: Number between 0-1 indicating the opacity of the shading on the subImages to help make the output image clearer. 0 is fully transparent shading (main image will be impossible to see), 1 is fully opaque (subImages will be impossible to make out). The default of 0.5 should be fine in most cases.
      • options.outputType?: string = 'png': The output type of the final mosaic. To preserve transparency in the image, use the default, 'png'.
      • options.outputWidth?: number = 400: Number of pixels the output mosaic's width will be (height will auto scale). The larger the width, the bigger the mosaic and the larger in size the final mosaic will be. The larger the output the longer it takes to generate a mosaic
      • options.algo?: 'closestColor' | 'random' = 'closestColor': How the subImages will be dispersed throughout when building the mosaic.
        • 'random' selects one of the subImages randomly each iteration to be inserted in that slice of the mosaic
        • 'closestColor' selects the subImage that is closest to the average color of the slice of the main image that the subImage is getting inserted to build the mosaic.

options.algo differences

closestColor

random

Methods

Assuming const photosaic = Photosaic(source, subImgs, opts), the methods below are exposed on photosaic

  • photosaic.build(): Promise<Buffer>: create a mosaic and return the result in a raw Buffer
  • photosaic.setSourceImage(newSrc: PhotosaicImage) => PhotosaicImage: reset source image created in mosaic
  • photosaic.setSubImages(subImgs: PhotosaicImage[]) => PhotosaicImage[]: reset subImages used to build mosaic
  • photosaic.addSubImage(img: PhotosaicImage): PhotosaicImage[]: add an image to the subImage list to build mosaic
  • photosaic.imgToStream(img: PhotosaicImage): Readable: convert a PhotosaicImage to a Readable stream
  • photosaic.imgToBuffer(img: PhotosaicImage): Promise<Buffer>: convert a PhotosaicImage to a raw Buffer

Tracking Mosaic Progress

Depending on the options provided (specifically gridNum and outputWidth) and the hardware you're running to build the mosaic, it could take several to tens of minutes for photosaic.build() to complete. Therefore, photosaic has an EventEmitter, photosaic.emitter you can listen for processing events to get the progress of the mosaic being built.

There will be a total of 2 * gridNum^2 iterations processed.

const photosaic = Photosaic(source, subImgs, opts)
photosaic.emitter.on('processing', (iteration) => {
  console.log(`Currently processing '${iteration}' subImage for the mosaic`)
})
await photosaic.build()

// Currently processing '1' subImage for the mosaic
// Currently processing '2' subImage for the mosaic
// Currently processing '3' subImage for the mosaic
// ...

CLI Task

You can use the following task to create a mosaic via the CLI with files on your local file system.

$ npm install -s photosaic
$ node ./node_modules/photosaic/dist/tasks/createMosaic.js -i ./pathToMosaicFile.js --dir ./path/to/sub/images -g 40 -w 1000

More Repositories

1

fndr

Password manager that stores your account information encrypted in data sources via connectors, including the Jupiter blockchain.
TypeScript
12
star
2

contracts

Smart contracts that are used in ok.let's.go. products & services.
Solidity
9
star
3

jupiter-git

Git server to support a backend of storing repos and files on the Jupiter blockchain
TypeScript
7
star
4

moontography

Single pane of glass platform for all Moontography products and services, powered by OKLG.
Vue
4
star
5

jupiter-node-sdk

A thin wrapper around the Jupiter blockchain APIs.
TypeScript
3
star
6

jupiter-fs

A small file system implementation for the Jupiter blockchain
TypeScript
3
star
7

moontography-web3

Common tasks to perform operations on the Ethereum blockchain.
TypeScript
3
star
8

blockchain-trusted-timestamping

Blockchain file timestamping web app to easily send digital signatures of files that can be validated they existed and have not changed since a particular time.
Vue
3
star
9

fndr-web

Web interface for fndr with the Jupiter connector in a browser instead of the CLI.
TypeScript
2
star
10

mcc-api

TypeScript
2
star
11

jupiter-sftp

A small SFTP server that allows browsing/downloading/uploading files stored on Jupiter.
TypeScript
2
star
12

oklg-api

Get real-time data points on supply, circulating supply, among other things for the OKLG project.
TypeScript
1
star
13

gud-guess

Gud Guess ($GG) is the first-of-its-kind Uniswap V3 TWAP-supported lottery style jackpot game that uses both skill and luck to win a weekly ETH jackpot.
Solidity
1
star
14

shed

Shed Coin (SHED) contracts
Solidity
1
star
15

BabyFlokiDoge

Solidity
1
star
16

mtgy-branding

All things branding for the moontography project.
1
star
17

mcc-v1-snapshot-api

MultiChainCapital v1 (0x1a7981d87e3b6a95c1516eb820e223fe979896b3) snapshot API at block 13711700
TypeScript
1
star
18

file-parser

Parse a file or buffer into to an easily consumable format.
TypeScript
1
star
19

browser-spreadsheet-parser

Parse spreadsheet files uploaded in the browser.
TypeScript
1
star
20

moontography-telegram-bot

Telegram bot for Moontography
TypeScript
1
star
21

defido

DeFido's v2 token contract
Solidity
1
star
22

upsurge-bot

Task to wait and immediately execute upsurge after the cooldown period for $SURGE on BSC.
TypeScript
1
star
23

cell

CellToken contract with supported marketing tax. (Original ETH 0x26c8afbbfe1ebaca03c2bb082e69d0476bffe099)
Solidity
1
star
24

oklg.io

Vue
1
star
25

moontography-api

Get real-time data points on supply, circulating supply, among other things for the MTGY project.
TypeScript
1
star