New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

@redbuck/cropper

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@redbuck/cropper

A tiny image cropper

latest
Source
npmnpm
Version
0.0.3
Version published
Maintainers
1
Created
Source

轻量截图库

使用

  • 安装: npm install @redbuck/cropper 或者 yarn add @redbuck/cropper.
  • 引入:
    • 模块化 commonjs: const Cropper = require('@redbuck/cropper'). ES6 module: import Cropper from "@redbuck/cropper".
    • CDN 页面中添加<script type="text/javascript" src="to/path/cropper.js"></script>
  • 使用:const cropper = new Cropper(el, options).

参数

字段类型默认值描述
elElement 丨 stringundefined截图组件挂载位置
optionsObject{}配置对象

options

字段类型默认值描述
urlstring""需要截取的图片地址
widthnumber600容器宽度
heightnumber375容器高度
windowobjectnull截图框的 rect
wheelSpeednumber0.05缩放步长
maxRatenumber10最大放大倍数
minRatenumber1最小放大倍数
cropModestring'cover'截图模式
maskColorstring'rgba(0,0,0,0.6)'蒙层颜色
devicePixelRationumberwindow.devicePixelRatiodpr

window 属性(window 类型可用)

字段类型默认值描述
xnumber0截图框的横坐标
ynumber0截图框的纵坐标
widthnumberoptions.width/2截图框的宽度
heightnumber0截图框的高度
resizeablebooleantrue是否允许改变截图框
moveablebooleantrue是否允许移动截图框
cropMode 详解
  • cover, 容器即截图框,图片只能在容器内部移动,最小只能缩小到容器的最长边.
  • contain, 容器即截图框,图片移动,缩放不限制
  • window, 显示截图框,截图框的移动限制在图片内(图片的缩放移动也受截图框的限制)
  • free-window,显示截图框,截图框的移动不受限制

API

output 同步输出 window 区域的图片

接口定义: output(options?: OutputType): string | Blob | Error; 参数定义:

type OutputType = {
  mime?: string,
  type?: string,
  quality?: number
};

moveTo 移动图片至指定位置

接口定义: moveTo(x: number, y: number): void;

zoom 在指定位置进行缩放

接口定义: zoom(origin: { x: number; y: number }, direction: number): void; 参数定义: origin 指缩放发生的坐标(canvas 坐标),delta 指方向(放大 1,缩小-1)

changeImage 更换图片

接口定义: changeImage(img: HTMLImageElement | string, callback?: Function):void

Keywords

cropper

FAQs

Package last updated on 11 Nov 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts