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

vue-image-handler

v1.2.9

Published

## Project setup ``` yarn install vue-image-handler```

Downloads

31

Readme

vue-image-handler

一个支持图片自定义裁剪和去底色的插件

github地址(感谢star)

预览效果

安装

npm install vue-image-handler
# 或者
yarn add vue-image-handler

vue项目中使用

// main.js
// 全局安装使用
import VueImageHandler from 'vue-image-handler'
Vue.use(VueImageHandler)

// 页面单独引入使用
import VueImageHandler from 'vue-image-handler'
// ...省略其他代码
components: { VueImageHandler }

Attributes

| 名称 | 功能 | 默认值 | 类型 | 可选值 | ----- | ----- | ----- | ----- | ----- | | canvas-width | 画布的宽度 | 380px | String | | | canvas-height | 画布的高度 | 252px | String | | |img-file | 图片资源 | | Blob/File/String|| |wipe-color| 要去除的底色||String|white/black| |color-diff|去底色的容差值|20|Number|1-100| |option|其他配置(具体配置参数见下表)||Object||

Option

| 名称 | 功能 | 默认值 | 类型 | 可选值 | ----- | ----- | ----- | ----- | ----- | | outputQuality | 处理后的图片质量 | 1 | Number | 0.1-1 | | outputType | 处理后的图片格式 | png | String | jpeg/png/webp | | canMove | 图片是否可以移动 | true | Boolean | true/false | | fixedBox | 固定截图框大小 | false | Boolean | true/false | | cropWidth | 截图框宽 | 380 | Number/String | 380 | | cropHeight | 截图框高 | 252 | Number/String | 252 |

Events(通过this.$refs[your ref name].[method]调用)

| 方法名 | 说明| 参数 | | ----- | ----- | ----- | | rotate | 旋转90° | | | download | 下载处理后的图片 | | | getImageUrl | 获取处理后的图片Base64 | | | clear | 清空画布和预览图 | | | refresh | 刷新画布 | |

快速上手

<template>
  <VueImageHandler
   ref="vueImageHandler"
   :canvas-width="width"
   :canvas-height="height"
   :img-file="imgFile"
   :wipe-color="wipeColor"
   :color-diff="colorDiff"
  />
</template>
<script>
 export default {
  data() {
    return {
      imgFile: 'https://cdn.jsdelivr.net/gh/cong1223/cloudimg@master/img/20210613092202.png',
      wipeColor: '',
      colorDiff: 20,
      width: '380px',
      height: '252px'
    };
  },
  methods: {
   changeCanvasWidth(e) { // 动态修改画布和预览图的宽度
      this.width = e.target.value + 'px';
      this.$refs.vueImageHandler.refresh();
    },
    changeCanvasHeight(e) { // 动态修改画布和预览图的高度
      this.height = e.target.value + 'px';
      this.$refs.vueImageHandler.refresh();
    },
    changeWipeColor(e) { // 动态修改要去的底色(white or black)
      this.wipeColor = e;
    },
    changeColorDiff(e) { // 动态修改去底色的容差值
      this.colorDiff = +e.target.value;
    },
    pickImage() { // 从本地选择图片(input file)
      this.$refs.filElem.dispatchEvent(new MouseEvent('click'));
    },
    handleRotate() { // 原图旋转
      this.$refs.vueImageHandler.rotate();
    },
    getFile() { // 从本地选择图片后获取文件信息
      const inputFile = this.$refs.filElem.files[0];
      if (inputFile) {
        this.imgFile = inputFile;
        this.$refs.filElem.value = '';
      } else {
        return;
      }
    },
    download() { // 下载图片
      this.$refs.vueImageHandler.download();
    },
    getUrl() {
      this.$refs.vueImageHandler.getImageUrl(url => {
        console.log('处理后的图片', url);
      });
    },
    clear() { // 清空画布
      this.$refs.vueImageHandler.clear();
    }
  }
 }
</script>

更新日志

1.2.9

支持页面内单独引用:`import VueImageHandler from 'vue-image-handler'`

即将更新

1. download和getImageUrl支持自定义图片格式输出