Gathering detailed insights and metrics for vue3-cropper
Gathering detailed insights and metrics for vue3-cropper
npm install vue3-cropper
Typescript
Module System
Node Version
NPM Version
60.8
Supply Chain
98
Quality
75.3
Maintenance
100
Vulnerability
99.6
License
Vue (79.81%)
JavaScript (18.71%)
HTML (1.48%)
Love this project? Help keep it running — sponsor us today! 🚀
Total Downloads
4,354
Last Day
5
Last Week
24
Last Month
161
Last Year
1,357
33 Stars
7 Commits
4 Forks
3 Watchers
1 Branches
1 Contributors
Updated on Dec 19, 2024
Latest Version
0.4.0
Package Id
vue3-cropper@0.4.0
Unpacked Size
1.56 MB
Size
389.41 kB
File Count
10
NPM Version
6.14.7
Node Version
14.8.0
Cumulative downloads
Total Downloads
Last Day
400%
5
Compared to previous day
Last Week
-31.4%
24
Compared to previous week
Last Month
4.5%
161
Compared to previous month
Last Year
43.3%
1,357
Compared to previous year
基于vue3.x开发的图片裁剪组件,可用于图片裁剪
不依赖任何第三方库,纯手工打造,功能强大,使用灵活。
npm install vue3-cropper -S
or
yarn add vue3-cropper
import { createApp } from 'vue'
import Cropper from "vue3-cropper";
import 'vue3-cropper/lib/vue3-cropper.css';
const app = createApp(App)
app.use(Cropper)
<input type="file" accept="image/*" @change="onChange"/>
<img v-if="previewImage" :src="previewImage" alt="预览图" style="max-width: 100%; max-height: 100%;">
<Cropper v-if="cropperVisible"
:imagePath="imagePath"
fileType="blob"
@save="onSave"
@cancel="onCancel"
/>
import {reactive, toRefs} from 'vue'
const URL = window.URL || window.webkitURL;
export default {
setup() {
const state = reactive({
cropperVisible: false,
imagePath: '',
previewImage: null
})
const onChange = (e) => {
const file = e.target.files[0]
state.imagePath = URL.createObjectURL(file);
state.cropperVisible = true
};
const onSave = (res) => {
if(typeof res === 'string')
{
state.previewImage = res
} else {
state.previewImage = URL.createObjectURL(res)
}
state.cropperVisible = false
};
const onCancel = () => {
state.cropperVisible = false
};
return {
...toRefs(state),
onChange,
onSave,
onCancel
};
}
}
tips:
选择图片后浏览器自动刷新问题:
这个问题是由于图片太大,超过了浏览器内存限制,被浏览器强制刷新释放内存导致的,可以适当的调整maxImgSize小一些,
内部会根据这个值创建一个图片进行裁剪(主要是手机端,pc一般不会出现这个问题)
截图质量:
如果要无损图可以设置imageType="image/png", 图片不会进行任何压缩,缺点是体积太大.
如果觉得截取的图片太大,可以设置imageType="image/jpeg",调整图片质量quality 0-1 数字越小图片质量越差,体积也会越小.
透明图片:
设置imageType="image/png",其他格式不支持透明
截图尺寸,清晰度问题:
默认输出原图尺寸,截取的部分是相对原图的那部分的尺寸,优点高清损耗低,缺点体积过大。
如果需要缩放尺寸,设置mode="scale" 就是图片缩放后在裁剪框内的那部分尺寸, 优点体积小,缺点损耗大
参数 | 说明 | 类型 | 默认值 |
---|---|---|---|
cropSize | 裁剪框默认大小 | Number | 200 |
imagePath | 裁剪图路径(可以是本地图片、图片数据源、远程图片需配置跨域) | string | |
fileType | 输出文件的类型(base64、blob) | String | base64 |
imageType | 输出图片的格式(image/jpeg、image/png、image/webp)其中 image/webp 只有 chrome 才支持 | String | image/jpeg |
quality | 输出图片的质量(0-1)并且只在格式为 image/jpeg 或 image/webp 时才有效,如果参数值格式不合法,将会被忽略并使用默认值。 | Number | .9 |
fixedBox | 固定裁剪框,设置true裁剪框不可修改 | Boolean | false |
showOutputSize | 展示输出图片的尺寸 | boolean | true |
mode | 裁剪模式(scale 缩放模式),不设置则按照原图尺寸输出 | String | |
maxImgSize | 图片最大尺寸(超过这个值会被自动压缩在这个范围内,保证手机端移动不会出现卡顿现象,如果不需要限制设置成null) | Number | 2000 |
参数 | 说明 | 类型 | 默认值 |
---|---|---|---|
cancel | 点击取消触发 | Function | |
save | 点击裁剪,处理完毕后触发,并携带裁剪好的图片数据 | (res)=>{} |
新增pc鼠标事件,可兼容pc端
新增图片最大尺寸限制:maxImgSize 解决移动端超大图片拖动卡顿现象。
新增自动识别图片方向,利用图片原始数据手动校正图片角度,避开浏览器校正, 解决各平台图片显示角度不一致的问题。
优化了裁剪流程,减少了canvas的使用。
新增裁剪模式mode="scale" 按照缩放后的尺寸输出图片。默认按照原图尺寸输出图片,
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
no SAST tool detected
Details
Reason
Found 0/7 approved changesets -- score normalized to 0
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
license file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
84 existing vulnerabilities detected
Details
Score
Last Scanned on 2025-02-17
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More