Giter VIP home page Giter VIP logo

clipper-image's Introduction

裁剪图片

clipperjs是一款非常强大却又简单的图片裁剪工具,它可以进行非常灵活的配置,支持手机端使用(关键是使用方法简单,几行代码就可以搞定)

演示示例

演示地址

PC端演示

手机端演示

特色功能

  • 同时对移动端pc端的支持
  • 支持commonjs、esmoudle和cdn的方式引入
  • 使用简单、傻瓜式操作

快速开始

安装

npm install clipper-image --save

引入

 import Clipper from 'clipper-image'

提示:也支持<script src="clipper-image.iife.js"></script>的方式引入

用法

添加1html容器

注意: 容器需要设置宽度和高度,容器的宽度作为滑块验证码的宽度

<div class="clipper" style="width: 800px; height: 480px;"></div>

创建控件

pc端推荐配置

const clipper = new Clipper({
	el: '.clipper'
})

clipper.setImgFile(file)

移动端推荐配置

const clipper = new Clipper({
	el: '.clipper',
	clipRect: {
		size: [0.8, 0.8],
		position: 'center',
		visible: true,
		isCanHidden: false, // 是否支持隐藏
		isCanResize: false, // 是否可以更改尺寸大小
		isCanPosition: false // 是否可以改变位置
	}
})

clipper.setImgFile(file)

配置项

名称 类型 默认值 必传 说明
el string | element 控件容器
onChange function 当裁剪位置(大小)发生变化时的回调 (参数1:裁剪图片的blob对象)
clipRect.size Array [0.5, 0.5] 裁剪区域初始化时默认大小;[0.5, 0.1] 横向宽度为父元素的1/2, 纵向宽度为父元素的 1/10; ['50px', '60px'] 横向宽度为50像素, 纵向宽度为 60像素;
clipRect.visible boolean false 裁剪区域初始化时是否隐藏
clipRect.position Array | 'center' 'center' 裁剪区域初始化时默认位置;[0.5, 0.1] 距离左边1/2, 距离顶部 1/10; ['50px', '60px'] 距离左边50像素, 距离顶部 60像素; center 自动计算后居中
clipRect.isCanHidden boolean true 裁剪区域是否可以隐藏
clipRect.isCanResize boolean true 裁剪区域是否可以自定义设置大小
clipRect.isCanPosition boolean true 裁剪区域是否可以改变位置

方法

方法名 返回值 示例 描述
setImgFile Promise setImgFile.reset(blob) 设置要裁剪的图片; blob为图片对象
getClipImage Promise clipper.getClipImage() 获取裁剪区域的blob对象
init clipper.init() 销毁控件后可以调用init方法重新显示裁剪画布
destory clipper.destory() 销毁控件

clipper-image's People

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.