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

cropic

v1.0.8

Published

移动端图片裁剪工具

Downloads

14

Readme

Cropic.js

移动端 h5 头像裁剪工具

此插件是根据微信头像裁剪进行演变,基于Clipic插件进行修改、更新

用手机访问此页面体验:https://tuao525.github.io/cropic/

或者用手机扫此二维码进入

avatar

npm 方式

$ npm install cropic

在 vue 项目里使用

// xxx.vue
<template>
  <img :src="base64" />
  <input type="file" name="file" accept="image/*" @change="uploadImg" />
</template>
<script>
  import Cropic from 'cropic'
  const cropic = new Cropic()
  export default {
    data () {
      return {
        base64: ''
      }
    }
    methods: {
      uploadImg(event) {
        const files = event.files
        const reader = new FileReader()
        reader.readAsDataURL(files[0])
        reader.onload = img => {
          cropic.getImage({
            width: 500,
            height: 400,
            src: img.target.result,
            name: 'cropic',
            encode: 'base64', // 支持 base64、blob、file
            type: 'png',
            // quality: '0.9', // 导出图片的质量
            // buttonText: ['Cancel', 'Reset', 'Done'],
            // buttonColor: ['#fff', '#3680fd', '#23c667'],
            // buttonSize: 12,
            onDone: base64 => {
              this.base64 = base64
            }
          })
        }
        event.value = ''
      }
    }
  }
</script>

在 react 项目里使用

import React, { useState } from 'react'
import Cropic from 'cropic'

export default () => {
  const [src, setSrc] = useState('')

  const cropBtn = (event) => {
    const cropic = new Cropic()
    const files = event?.target.files
    const reader = new FileReader()
    reader.readAsDataURL(files[0])
    reader.onload = (img) => {
      cropic.getImage({
        // width: 500,
        // height: 500,
        src: img?.target?.result,
        name: 'cropic',
        encode: 'base64', // 支持 base64、blob、file
        type: 'png',
        // quality: '0.9', // 导出图片的质量
        // buttonText: ['Cancel', 'Reset', 'Done'],
        // buttonColor: ['#fff', '#3680fd', '#23c667'],
        // buttonSize: 12,
        onDone: (base64) => {
          setSrc(base64)
        },
        onCancel: function () {
          console.log('取消裁剪')
        }
      })
    }
  }
  return (
    <div>
      <img
        src={src}
        style={{ width: '100px', height: '100px', borderRadius: '50%' }}
      />
      <input type="file" name="file" accept="image/*" onChange={cropBtn} />
    </div>
  )
}

cdn 方式

<!-- xxx.html -->
<script src="https://unpkg.com/cropic/dist/cropic.min.js"></script>
<script>
  var cropic = new Cropic()
  cropic.getImage({
    // width: 500,
    // height: 400,
    src: e.target.result,
    name: 'cropic',
    encode: 'base64', // 支持 base64、blob、file
    type: 'png',
    // quality: '0.9', // 导出图片的质量
    // buttonText: ['Cancel', 'Reset', 'Done'],
    // buttonColor: ['#fff', '#3680fd', '#23c667'],
    // buttonSize: 12,
    onDone: function (e) {
      document.getElementById('previewImg').src = e
    },
    onCancel: function () {
      console.log('取消裁剪')
    }
  })
</script>

参数说明

| 字段 | 类型 | 必填 | 默认 | 说明 | | :---------- | :----- | :--- | :-------------------------------- | :------------------------------------------ | | width | Number | | 500 | 裁剪宽度 | | height | Number | | 500 | 裁剪高度 | | src | String | 是 | | 需要裁剪的图片,可以是图片链接,或者 base64 | | type | String | | jpeg | 裁剪后图片的类型,仅支持 jpeg/png 两种 | | quality | Number | | 0.9 | 压缩质量(0.1-1) | | buttonText | Array | | ['取消', '重置', '完成'] | 底部三个按钮文本 | | buttonColor | Array | | ['#e04c4c', '#3680fd', '#23c667'] | 底部三个按钮文本的颜色 | | buttonSize | String | | 12 | 底部三个按钮文本的大小 | | name | String | | cropic | 如果导出编码为 file,则可填图片名 | | encode | String | | base64 | 导出的格式,支持 base64、blob、file |

事件说明

| 事件 | 回调 | 说明 | | :------- | :------------------- | :------- | | onDone | 导出裁剪后的图片编码 | 完成裁剪 | | onCancel | 无 | 取消裁剪 |