npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

image-merger-by-steps

v1.5.1

Published

A TypeScript module to load and merge images on the canvas with control over the merging steps.

Downloads

23

Readme

image-merger-by-steps

Merging a series of images all at one time on low-end devices can be painful. Here is the solution. A TypeScript module to load and merge images on the canvas with control over the merging steps.

Features

  • Customizable Steps: Define the steps and configurations for merging.
  • Supports Various Formats: Merge images in different formats such as JPEG and PNG
  • Supports For Image Customization: Setting the position, size, and opacity for each layer image.

Options

Merger Options:

| Key | Type | Description | | ----------- | :-----------------------------: | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------: | | slices | number[] | An array of numbers defining the slices. For example, [2, 1] will process the first two images together in one step, and then the next image in a separate step. If there were more images, they would be processed together. | | canvasSizes | {width: number, height: number} | Object defining the canvas size | | format | string | Output format of the merged image (options: 'jpg', 'jpeg', 'png') |

Layer Options

| Key | Type | Description | | ------- | :----: | -----------------------------------------------------: | | x | number | set the horizontal position of the image on the canvas | | y | number | set the vertical position of the image on the canvas | | size | number | set the scale of the image | | opacity | number | Number to set the opacity of the image (0 to 1) |

Installation

You can install the package via npm:

npm install image-merger-by-steps

Usage

Here is an example of how to use image-merger-by-steps(checkout /example folder):

import ImageMerger from "image-merger-by-steps";

// Make sure the code below is running in a browser environment,
// because the ImageMerger class uses the HTMLCanvasElement
const imageMerger = new ImageMerger();

const layers1 = [
  { src: "image1.png", x: 0, y: 0, size: 1, opacity: 1 }, // Here goes the LayerOptions
  { src: "image2.png", x: 0, y: 1000, size: 1, opacity: 1 },
  { src: "image3.png", x: 0, y: 0, size: 1, opacity: 1 },
];
const layers2 = [
  { src: "image4.png", x: 0, y: 0, size: 1, opacity: 1 },
  { src: "image5.png", x: 0, y: 1000, size: 1, opacity: 1 },
  { src: "image6.png", x: 0, y: 0, size: 1, opacity: 1 },
];
const images = [layers1, layers2, layers1, layers2, layers1]; // Array of layers for each image

imageMerger
  .merge(images, {
    format: "png", // Here goes the MergerOptions
    slices: [2, 2, 1],
  })
  .then((base64Images) => {
    // Put base64 into img -src- attribute
    base64Images.forEach((base64) => {
      const img = document.createElement("img");
      img.src = base64;
      const exampleElement = document.getElementById("example");
      if (exampleElement) exampleElement.appendChild(img);
    });
  });
import ImageMerger, { Layer } from "image-merger-by-steps";

// Make sure the code below is running in a browser environment,
// because the ImageMerger class uses the HTMLCanvasElement
const imageMerger = new ImageMerger();
const layers1: Layer[] = [
  { src: "image1.png", x: 0, y: 0, size: 1, opacity: 1 }, // Here goes the LayerOptions
  { src: "image2.png", x: 0, y: 1000, size: 1, opacity: 1 },
  { src: "image3.png", x: 0, y: 0, size: 1, opacity: 1 },
];
const layers2: Layer[] = [
  { src: "image4.png", x: 0, y: 0, size: 1, opacity: 1 },
  { src: "image5.png", x: 0, y: 1000, size: 1, opacity: 1 },
  { src: "image6.png", x: 0, y: 0, size: 1, opacity: 1 },
];
const images: Layer[][] = [layers1, layers2, layers1, layers2, layers1]; // Array of layers for each image

imageMerger
  .merge(images, {
    format: "png", // Here goes the MergerOptions
    slices: [2, 2, 1],
  })
  .then((base64Images) => {
    // Put base64 into img -src- attribute
    base64Images.forEach((base64) => {
      const img = document.createElement("img");
      img.src = base64;
      const exampleElement = document.getElementById("example");
      if (exampleElement) exampleElement.appendChild(img);
    });
  });

Contact

For any questions or feedback, please open an issue on GitHub or contact my email