1.0.7 • Published 5 years ago

dealimage v1.0.7

Weekly downloads
4
License
ISC
Repository
github
Last release
5 years ago

dealimage

Using canvas to process pictures

npm i dealimage --save

html

 <canvas id="canvas"></canvas>
 <p><img src="" alt=""></p>
 <input type="file" name="" value="">

js

var inputEle = document.querySelector("input");
inputEle.addEventListener("change", function() {

  var img = new DealImage({
      target: "#canvas",
      mosaicSize: 10,
      image: "https://avatars1.githubusercontent.com/u/25859283?v=4"
  })

  img.draw({
      type: "image/png",
      mosaic: {
          position: [
              {start: [50, 50], end: [150, 150]},
              {start: [200, 200], end: [300, 300]},
          ],
      },
      frame: {
          position: [
              {start: [50, 50], end: [150, 150]},
              {start: [200, 200], end: [300, 300]},
          ],
          color: "red"
      },
      callback: function(imgBase64, filename) {

          let imgEle = document.querySelector("img"),
              linkEle = document.createElement("a");

          imgEle.src = imgBase64;

          /*
          下载图片
           */
          // linkEle.style.display = "none";
          // linkEle.download = filename;
          // linkEle.href = imgBase64;

          // document.body.appendChild(linkEle);
          // linkEle.click();
          // // 然后移除
          // document.body.removeChild(linkEle);
      }
  })
})
1.0.7

5 years ago

1.0.6

5 years ago

1.0.5

5 years ago

1.0.4

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago