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

tnuiv3p-tn-image-crop

v1.0.5

Published

TuniaoUI vue3 uniapp 插件

Downloads

39

Readme

图鸟 UI vue3 uniapp Plugins - 图片裁剪

TuniaoUI vue3 uniapp

Tuniao UI vue3官方仓库

该组件适用于用户选择图片之后,对图片进行裁剪,裁剪完成之后,返回裁剪后的图片临时地址或者base64的数据

组件安装

npm i tnuiv3p-tn-image-crop

组件位置

import TnImageCrop from 'tnuiv3p-tn-image-crop/index.vue'

平台差异说明

| App(vue) | H5 | 微信小程序 | 支付宝小程序 | ... | | :------: | :-: | :--------: | :----------: | :----: | | √ | √ | √ | √ | 适配中 |

基础使用

该组件默认取用户设置的容器的宽高,然后根据宽高的比例设置裁剪框的尺寸,组件并不是全屏的,所以需要用户自己设置容器的宽高

  • 通过src传递待裁剪的图片地址
  • 设置circle设置是否裁剪后的图片为圆形
<script setup lang="ts">
const image = 'https://resource.tuniaokj.com/images/content/rodion.jpg'
</script>

<template>
  <view class="content">
    <TnImageCrop :src="image" />
  </view>
</template>

<style>
.content {
  position: relative;
  width: 100%;
  height: 100vh;
}
</style>

获取裁剪后的图片

  • 通过调用组件的save方法,可以获取裁剪后的图片的临时地址或者base64的数据

save方法传递一个options参数来设置对应生成图片的参数

options属性说明

| 属性名称 | 属性说明 | 属性类型 | 默认值 | | --------- | -------------------------------------------- | -------- | ------ | | base64 | 返回base64格式的图片,H5端默认返回base64格式 | boolean | false | | cropRatio | 裁剪后的图片与原图片的比例, 范围0 ~ 1 | number | 1 | | quality | 裁剪后图片的质量, 范围0 ~ 1 | number | 1 |

<script setup lang="ts">
import { ref } from 'vue'
import TnButton from '@tuniao/tnui-vue3-uniapp/components/button/src/button.vue'
import type { TnImageCropInstance } from 'tnuiv3p-tn-image-crop'

const imageCropRef = ref<TnImageCropInstance>()

const image = 'https://resource.tuniaokj.com/images/content/rodion.jpg'

// 获取裁剪后的图片
const saveImage = async () => {
  const imageData = await imageCropRef.value?.save({
    base64: false,
  })
  // eslint-disable-next-line no-console
  console.log(imageData)
}
</script>

<template>
  <view class="content">
    <TnImageCrop :src="image" />
  </view>
  <view class="button">
    <TnButton size="xl" @click="saveImage">保存图片</TnButton>
  </view>
</template>

<style>
.content {
  position: relative;
  width: 100%;
  height: 100vh;
}
.button {
  position: fixed;
  z-index: 1000;
  left: 50%;
  bottom: 50rpx;
  transform: translate(-50%, -50%);
}
</style>

API

Props

| 属性名 | 说明 | 类型 | 默认值 | 可选值 | | ------------ | ------------------------------------------ | ------- | -------------------- | ------------------------------------------------------------ | | src | 图片地址 | String | - | - | | circle | 圆形裁剪框 | Boolean | false | true | | border-color | 裁剪框边框颜色,以tn开头使用图鸟内置的颜色 | String | #fff | 边框颜色 | | bg-color | 容器背景颜色,以tn开头使用图鸟内置的颜色 | String | rgba(0, 0, 0, 0.5) | 背景颜色 | | z-index | zIndex | Number | 100 | - | | min-scale | 最小缩放系数 | Number | 0.5 | - | | max-scale | 最大缩放系数 | Number | 2 | - |

Expose

| 函数名 | 函数说明 | 函数类型 | | ------ | -------- | ---------------------------------------------------- | | save | 保存图片 | (options?: GenerateImageOption) => Promise<string> |

GenerateImageOption

| 属性名称 | 属性说明 | 属性类型 | 默认值 | | --------- | -------------------------------------------- | -------- | ------ | | base64 | 返回base64格式的图片,H5端默认返回base64格式 | boolean | false | | cropRatio | 裁剪后的图片与原图片的比例, 范围0 ~ 1 | number | 1 | | quality | 裁剪后图片的质量, 范围0 ~ 1 | number | 1 |