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-picture-transform

v1.0.9

Published

Vue移动端,图片自由变换组件

Downloads

4

Readme

vue-picture-transform

本组件为VUE移动端,图片自由变换组件,暂时仅支持移动端。

1

安装

npm i -S vue-picture-transform

属性

| 属性 | 类型 | 默认值 | 说明 | | ---------- | ------ | ------ | ---------------------------------------------- | | size | Number | 100 | 操作框大小默认100*100 | | zIndex | Number | 1 | 操作框zIndex | | maxScale | Number | 3 | 最大放大倍率 | | minScale | Number | 0.2 | 最小缩放倍率 | | disabled | Number | false | 禁用操作框 | | imgUrl | String | | 初始化图片地址(可不传,之后调用init方法来传) | | id | String | | 初始化ID(可不传,之后调用init方法来传) |

事件

| 事件 | 说明 | 参数 | 参数说明 | | -------- | ---------------- | ---- | -------------------- | | close | 点击叉号关闭事件 | id | 初始化传进来的initId | | selected | 选中事件 | id | 初始化传进来的initId |

组件方法

| 组件方法 | 说明 | 返回值 | | ------------------ | ---------------------- | ----------- | | init(imgUrl,id) | 设置一张图片和ID | 空 | | getTransformInfo() | 获取变变形后的图片信息 | {center:{x,y},width,height,scale,rotate,id,imgUrl,img} |

单个组件使用方式:

<template>
  <div id="app">
    <VuePictureTransform ref="transform"></VuePictureTransform>
    <button @click="getInfo">getInfo</button>
  </div>
</template>
<script>
import VuePictureTransform from 'vue-picture-transform'
import imgUrl from './assets/logo.png'
export default {
  name: 'app',
  components: {
    VuePictureTransform,
  },
  mounted(){
    this.$refs.transform.init({
      imgUrl: imgUrl
    })
  },
  methods: {
    getInfo(){
      console.log(this.$refs.transform.getTransformInfo())
    }
  }
}
</script>

多个组件使用,并拼接到canvas上

<template>
      <div ref='avatar' :style="{backgroundImage: 'url('+avatar+')'}">
        <PicTrancform
          ref="decorateList"
          v-for="item in useDecorateList"
          :key="item.id"
          :disabled="!(item.id === active)"
          :imgUrl="item.img"
          :id="item.id"
          :zIndex="item.zIndex"
          @close="close(item.id)"
          @selected="selected(item.id)"
        />
      </div>
</template>
<script>
import PicTrancform from 'vue-picture-transform'

export default {
  components: {
    PicTrancform
  },
  data(){
    return {
      useDecorateList: [],// 图片列表
      active:0, //当前操作图片
      avatar: '',// 背景图片地址
      avatarImg: null,// 背景图片imgData
      canvas: null,//画布
      ctx: null,// 上下文
      canvasInfo:{ 
        width: 240,// 画布宽度
        height: 240,// 画布高度
        scale: 2 // 生成图片放大比例
      },
    }
  },
  mounted(){
    this.canvas = this.$refs.canvas // 设置一个canvas元素。
    this.ctx = this.canvas.getContext('2d')
  },
  methods: {
    ...
    getDecorateList(){
      let list = []
      let components = this.$refs.decorateList
      if(Array.isArray(components)) {
        list = components.map(item => {
          return item.getTransformInfo()
        })
      }
      return list
    },
    mergeImg(){
      let canvas = this.canvas
      let ctx = this.ctx
      let {width,height,scale} = this.canvasInfo
      ctx.clearRect(0,0,width*scale,height*scale)
      let avatarImg = this.avatarImg
      ctx.drawImage(avatarImg,0,0,width*scale,height*scale)
      let decorateList = this.getDecorateList()
      decorateList.forEach(decorate => {
        ctx.save() // 保存当前状态
        ctx.translate(decorate.center.x*scale,decorate.center.y*scale)
        ctx.rotate(decorate.rotate*Math.PI/180)
        ctx.scale(decorate.scale,decorate.scale)
        ctx.drawImage(decorate.img,-1* ~~(decorate.width*scale/2),-1* ~~(decorate.height*scale/2),decorate.width*scale,decorate.height*scale)
        ctx.restore()
      })
      // 使用toDataUrl可以获取拼接图片
    }
}
</script>