GithubHelp home page GithubHelp logo

lfb / composite-image Goto Github PK

View Code? Open in Web Editor NEW

This project forked from fantasygao/composite-image

0.0 1.0 0.0 338 KB

Combine multiple images into one image

License: MIT License

JavaScript 80.45% TypeScript 17.22% HTML 2.33%

composite-image's Introduction

CompositeImage 多图合并

介绍

支持多图合并,合并后下载。

安装

npm i --save composite-image

用法

import CompositeImage from 'composite-image';

/**
 * @description 生成一张长300 宽400的画布
 * @bgWidth 画布宽
 * @bgHeight 画布高
 **/ 
const image = new CompositeImage({
  bgWidth: 300,  // 合成后图片的宽度
  bgHeight: 400,  // 合成后图片的高度
});

/**
 * @description 第一张图片
 * @src 图片链接
 * @x 相对于画布的x坐标
 * @y 相对于画布的y坐标
 * @width 图片的宽
 * @height 图片的高
 */ 
const cfg1 = {
  src: 'https://bpic.588ku.com/back_pic/19/04/14/bf310e139cf9fc16b3c032caccf6804a.jpg',
  x: 0,
  y: 0,
  width: 300,
  height: 300
};

/**
 * @description 第二张图片
 * @src 图片链接
 * @x 相对于画布的x坐标
 * @y 相对于画布的y坐标
 * @width 图片的宽
 * @height 图片的高
 */ 
const cfg2 = {
  src: 'https://ss1.bdstatic.com/70cFvXSh_Q1YnxGkpoWK1HF6hhy/it/u=1805103632,2396162225&fm=26&gp=0.jpg',
  x: 90,
  y: 70,
  width: 116,
  height: 116
};

// 合并操作,可支持传入多个图片
image.composite(cfg1, cfg2).then(() => {
  image.print(); // 图片地址dataUrl格式,可传入生成图片类型,默认'png'
  image.download('image.png'); // 将已生成图片下载至本地,可传入导出的文件名
})

入参图片

结果

合并结果

License

This code is distributed under the MIT License.

composite-image's People

Contributors

fantasygao avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.