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

taro-image-clipper

v1.0.2

Published

小程序图片裁剪器,基于Taro

Downloads

8

Readme

taro-image-clipper

小程序图片裁剪器,基于Taro

特点

  1. 使用简单,样式简洁
  2. 支持图片缩放
  3. 支持自定义裁剪框宽高
  4. 支持自定义放大倍数
  5. 缩放、裁剪流畅

效果

安装

npm install taro-image-clipper

引入

import { ImageClipper } from 'taro-image-clipper'

使用

基础

// 是否展示裁剪器
const [showClipper, setShowClipper] = useState(false)
// 选择的原始图片
const [originalImage, setOriginalImage] = useState("")
// 裁剪后图片
const [clippedImage, setClippedImage] = useState("")

<ImageClipper
  visible={showClipper}
  src={originalImage}
  onCut={(imgPath) => {
    setClippedImage(imgPath)
    setShowClipper(false)
  }}
  onCancel={() => {
    setShowClipper(false)
  }}
/>

完整使用demo

import { View, Button, Image } from "@tarojs/components"
import Taro from "@tarojs/taro"
import { useState } from "react"
import { ImageClipper } from 'taro-image-clipper'

// 图片裁剪使用Demo
export default () => {
  // 是否展示裁剪器
  const [showClipper, setShowClipper] = useState(false)
  // 选择的原始图片
  const [originalImage, setOriginalImage] = useState("")
  // 裁剪后图片
  const [clippedImage, setClippedImage] = useState("")

  return (
    <View >
      <View style={{ padding: '20rpx' }}>
        {/* 选择图片按钮 */}
        <Button
          onClick={() => {
            Taro.chooseImage({
              count: 1,
            }).then((res) => {
              setShowClipper(true)
              setOriginalImage(res.tempFilePaths[0])
            })
          }}
        >
          选择图片
        </Button>
        <View style={{ margin: '20px 0' }}>裁剪结果:</View>
        {/* 裁剪结果展示 */}
        <Image
          src={clippedImage}
          style={{
            borderRadius: "16rpx",
            height: "500rpx",
            width: "500rpx",
          }}
        />
      </View>
      {/* 裁剪组件 */}
      <ImageClipper
        visible={showClipper}
        src={originalImage}
        onCut={(imgPath) => {
          setClippedImage(imgPath)
          setShowClipper(false)
        }}
        onCancel={() => {
          setShowClipper(false)
        }}
      />
    </View>
  )
}

参数说明

| 参数 | 类型 | 默认值 | 必填 | 说明 | | :--------- | :--------- | ----------- | :--: | :--------------------- | |visible | boolean | 无 | 是 | 是否展示图片裁剪器 | |src | string | 无 | 是 | 要裁剪的图片 | |clipperWidth | number | 500 | 否 | 裁剪框宽度 | |clipperHeight | number | 500 | 否 | 裁剪框高度 | |maxScale | number | 5 | 否 | 最大放大倍数,maxScale >= 1| |fileType | string | jpg | 否 | 裁剪后导出的图片的格式,只支持 'jpg' 或 'png' | |quality | number | 1 | 否 | 导出图片的质量,取值为 0 ~ 1 | |clipperCutCanvasId| string | clipperCutCanvasId | 否 | 用于裁剪的canvas id | | onCut | (imgPath: string) => void | ( ) => { }| 否 | 点击底部的完成按钮,执行裁剪,成功则触发该回调 | | onCancel | ( ) => void | ( ) => { } | 否 | 点击取消按钮回调 |