1.1.0 • Published 6 years ago

element2canvas v1.1.0

Weekly downloads
1
License
ISC
Repository
github
Last release
6 years ago

element2canvas

a plugin for canvert elements like iamge, text and so on to a canvas or image, screenshot and so on. It's a little plugin by js and never need to compute DOM properties, so it could have nealy 99% degree of reduction. From the interface It's very convenience.


Install

npm install elment2canvas --save or <script src="path/to/index.min.js"></script>


Usage

detail in exzample

  var canvas = new element2canvas(opts)
  canvas.init().then(() => {
    return canvas.add(opts)
  }).then(() => {
    var img = document.createEelement('img')
    img.src = canvas.toDataURL('image/jpeg', 0.8)
    img.onload = () => {
      (document.body || document.documentElement).appendChild(img)
    }
  }) 

configuration properties options

propertiesinstructiontypedefault
widthcanvas's widthnumber0
heightcanvas's heightnumber0
zIndexlike css z-index propertynumber0
containercanvas Element be appended instring / DOMbody
backgroundbackground color or imagestringtransparent
crossOriginimage security statesring(anonymous)none
elementselement in canvasarraynone

element properties

propertiesinstructiontypedefault
widthelement's widthnumber0
heightelement's heightnumber0
zIndexlike css z-index propertynumber0
toppostion like css propertynumber0
bottompostion like css propertynumber0
leftpostion like css propertynumber0
rightpostion like css propertynumber0
srcimage srcstringnone
texttext contentstringnone
fontSizefont-size like css propertynumber12
fontFamilyfont-family like css propertystringnone
colorfont colorstringnone

instance's methods

methodinstructionreturnparams
initinitialize the cavans and append to DOMPromise
toDataURLcavans to image of base64image of base64type(image/jpeg, ...), quality
addadd a element to canvasPromiseelement