All Projects → lukechilds → Merge Images

lukechilds / Merge Images

Licence: mit
Easily compose images together without messing around with canvas

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Merge Images

Lena.js
👩 Library for image processing
Stars: ✭ 432 (-63.14%)
Mutual labels:  image-manipulation, canvas
Canvacord
Powerful image manipulation tool to manipulate images easily.
Stars: ✭ 87 (-92.58%)
Mutual labels:  image-manipulation, canvas
Jspaint
🎨 Classic MS Paint, REVIVED + ✨Extras
Stars: ✭ 5,972 (+409.56%)
Mutual labels:  image-manipulation, canvas
Pixelcraft
A Pixel Art Editor
Stars: ✭ 413 (-64.76%)
Mutual labels:  image-manipulation, canvas
Mopaint
🎨💪 Modern, modular paint and more! (pre-alpha, not much done yet)
Stars: ✭ 50 (-95.73%)
Mutual labels:  image-manipulation, canvas
Watchcarslearn
Self driving cars using NEAT
Stars: ✭ 59 (-94.97%)
Mutual labels:  canvas
Dna Gan
DNA-GAN: Learning Disentangled Representations from Multi-Attribute Images
Stars: ✭ 65 (-94.45%)
Mutual labels:  image-manipulation
React Easy Crop
A React component to crop images/videos with easy interactions
Stars: ✭ 1,093 (-6.74%)
Mutual labels:  image-manipulation
React Handy Renderer
✏️ Draw 2D primitives in sketchy style with React
Stars: ✭ 56 (-95.22%)
Mutual labels:  canvas
Dazv
canvas 可视化图表
Stars: ✭ 70 (-94.03%)
Mutual labels:  canvas
Pasition
Path Transition with little JS code, render to anywhere - 轻量级 Path 过渡库,渲染到任何地方
Stars: ✭ 1,149 (-1.96%)
Mutual labels:  canvas
Notation
✏️ A simple web app to make drawings that are easy to embed, particularly for Notion.so.
Stars: ✭ 63 (-94.62%)
Mutual labels:  canvas
Elm Canvas
Making the canvas API accessible within Elm
Stars: ✭ 60 (-94.88%)
Mutual labels:  canvas
Sketches
a starting point for sketches
Stars: ✭ 66 (-94.37%)
Mutual labels:  canvas
Svelte Canvas
🎨 Reactive canvas rendering with Svelte.
Stars: ✭ 59 (-94.97%)
Mutual labels:  canvas
Animockup
Create animated mockups in the browser 🔥
Stars: ✭ 1,152 (-1.71%)
Mutual labels:  canvas
Calendar Graph
Calendar graph like github using jsx support SVG, Canvas and SSR
Stars: ✭ 58 (-95.05%)
Mutual labels:  canvas
Canvas
High performance skia binding to Node.js. Zero system dependency and pure npm packages without any postinstall scripts nor node-gyp.
Stars: ✭ 63 (-94.62%)
Mutual labels:  canvas
Zdog
Flat, round, designer-friendly pseudo-3D engine for canvas & SVG
Stars: ✭ 8,904 (+659.73%)
Mutual labels:  canvas
Popbot
Color splash effects using Deep Learning
Stars: ✭ 61 (-94.8%)
Mutual labels:  image-manipulation

merge-images

Easily compose images together without messing around with canvas

Build Status Coverage Status npm npm

Canvas can be kind of a pain to work with sometimes, especially if you just need a canvas context to do something relatively simple like merge some images together. merge-images abstracts away all the repetitive tasks into one simple function call.

Images can be overlaid on top of each other and repositioned. The function returns a Promise which resolves to a base64 data URI. Supports both the browser and Node.js.

Install

npm install --save merge-images

or for quick testing:

<script src="https://unpkg.com/merge-images"></script>

Usage

With the following images:

/body.png /eyes.png /mouth.png

You can do:

import mergeImages from 'merge-images';

mergeImages(['/body.png', '/eyes.png', '/mouth.png'])
  .then(b64 => document.querySelector('img').src = b64);
  // data:image/png;base64,iVBORw0KGgoAA...

And that would update the img element to show this image:

Positioning

Those source png images were already the right dimensions to be overlaid on top of each other. You can also supply an array of objects with x/y co-ords to manually position each image:

mergeImages([
  { src: 'body.png', x: 0, y: 0 },
  { src: 'eyes.png', x: 32, y: 0 },
  { src: 'mouth.png', x: 16, y: 0 }
])
  .then(b64 => ...);
  // data:image/png;base64,iVBORw0KGgoAA...

Using the same source images as above would output this:

Opacity

The opacity can also be tweaked on each image.

mergeImages([
  { src: 'body.png' },
  { src: 'eyes.png', opacity: 0.7 },
  { src: 'mouth.png', opacity: 0.3 }
])
  .then(b64 => ...);
  // data:image/png;base64,iVBORw0KGgoAA...

Dimensions

By default the new image dimensions will be set to the width of the widest source image and the height of the tallest source image. You can manually specify your own dimensions in the options object:

mergeImages(['/body.png', '/eyes.png', '/mouth.png'], {
  width: 128,
  height: 128
})
  .then(b64 => ...);
  // data:image/png;base64,iVBORw0KGgoAA...

Which will look like this:

Node.js Usage

Usage in Node.js is the same, however you'll need to also require node-canvas and pass it in via the options object.

const mergeImages = require('merge-images');
const { Canvas, Image } = require('canvas');

mergeImages(['./body.png', './eyes.png', './mouth.png'], {
  Canvas: Canvas,
  Image: Image
})
  .then(b64 => ...);
  // data:image/png;base64,iVBORw0KGgoAA...

One thing to note is that you need to provide a valid image source for the node-canvas Image rather than a DOM Image. Notice the above example uses a file path, not a relative URL like the other examples. Check the node-canvas docs for more information on valid Image sources.

API

mergeImages(images, [options])

Returns a Promise which resolves to a base64 data URI

images

Type: array
Default: []

Array of valid image sources for new Image().
Alternatively an array of objects with x/y co-ords and src property with a valid image source.

options

Type: object

options.format

Type: string
Default: 'image/png'

A DOMString indicating the image format.

options.quality

Type: number
Default: 0.92

A number between 0 and 1 indicating image quality if the requested format is image/jpeg or image/webp.

options.width

Type: number
Default: undefined

The width in pixels the rendered image should be. Defaults to the width of the widest source image.

options.height

Type: number
Default: undefined

The height in pixels the rendered image should be. Defaults to the height of the tallest source image.

options.Canvas

Type: Canvas
Default: undefined

Canvas implementation to be used to allow usage outside of the browser. e.g Node.js with node-canvas.

options.crossOrigin

Type: string
Default: undefined

The crossOrigin attribute that Image instances should use. e.g Anonymous to support CORS-enabled images.

License

MIT © Luke Childs

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].