![Oracle Drags Its Feet in the JavaScript Trademark Dispute](https://cdn.sanity.io/images/cgdhsj6q/production/919c3b22c24f93884c548d60cbb338e819ff2435-1024x1024.webp?w=400&fit=max&auto=format)
Security News
Oracle Drags Its Feet in the JavaScript Trademark Dispute
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
image-process
Advanced tools
Image pre processing for upload (html5 + canvas), ie10+
解决图片上传前裁剪、等比缩放,支持本地视频、同域视频文件截图功能等。
裁剪图片:同时设置参数width, height
等比缩放:按宽度缩放,只设置width; 同理按高度缩放,只需设置height
不裁剪、不缩放,直接返回源文件base64数据
视频截图返回数据中含有字段videoFile
, videoWidth
, videoHeight
, duration
。其他参数为截图参数
npm install image-process --save-dev
ES6+
import { ZxImageProcess } from 'image-process'
const zxImageProcess = new ZxImageProcess({
// 默认为空,图片和视频文件,前提是浏览器支持input[accept=]
accept: 'video/*',
// 自动裁剪
auto: false,
// 触发文件选择的元素
selector: '#buttonId',
// 限制宽度等比缩放,则只需设置width值
// 限制高度等比缩放,则只需设置height值
// 同时设置了width、height值,则会对图片按尺寸裁剪
width: 600,
height: 400,
// 裁剪容器按钮样式
submitStyle: '',
cancelStyle: 'color: red',
// 最大文件限制
maxSize: 50,
success: function (result) {
// 返回数据
console.log(result);
},
error: function (err) {
console.error(err);
}
})
不初始化ZxImageProcess,直接使用期内部方法handleImageFile(file, options)
和handleVideoFile(file, options)
,返回promise对象
import { handleMediaFile } from 'image-process'
const options = {
width: 600,
height: 400,
// 文件大小限制50M
maxSize: 50
}
// 处理图片或视频文件
handleMediaFile(file, options)
.then(res => {
console.log(res)
})
.catch (err => {
console.error(err)
})
browser
<script src="./dist/image-process-tools.min.js"></script>
https://capricorncd.github.io/image-process-tools/dist
auto true|false
自动处理图片,裁剪时不弹出手动位置调整框。默认为false。
selector: #buttonId
选择图片按钮id,支持id、class选择器,或者HTMLElement
对象(仅ZxImageProcess实例化时有效)
width: 640
裁剪或缩放宽度为640px(可选)
1.限制宽度缩放,则只需设置width值。
2.限制高度缩放,则只需设置height值。
3.同时设置了width、height值,则会对图片按尺寸裁剪
height: 640
裁剪或缩放高度为640px(可选)
maxSize: 50
文件大小最大限制,单位M(兆)
success: function(result){ console.log(result) }
图片处理完成后的回调函数(仅ZxImageProcess实例化时有效)
base64:
base64
图片base64数据
blob:
blobData
处理成功的图片数据,可直接上传至服务器,或赋值给input利用form表单提交。
element:
canvas
canvas节点对象
height:
640
处理完成的图片宽度
width:
640
处理完成的图片宽度
url:
blob:url
raw:
Object
原图片相关属性(宽高/文件大小/Base64编码数据/类型/元素节点)
size:
21100
处理完成的图片文件大小
type:
image/png
处理完成的图片类型
error: function(err){ alert(err.message); }
处理过程中的错误或警告回调函数(仅ZxImageProcess实例化时有效)
submitStyle: color: #f00
裁剪框确认按钮样式(仅ZxImageProcess实例化时有效)
cancelStyle: color: #f00
裁剪框取消按钮样式(仅ZxImageProcess实例化时有效)
conversion(size) 将size单位B转换为KB或M(大于1024KB则返回M)
toBlobData(base64) base64转blob
toBlobUrl(file|blob) 文件数据转blob url
reCrop() 重新显示图片裁剪窗口,重新调整裁剪图片
code | message说明 |
---|---|
1 | 初始化参数selector 不合法,非有效字符串 |
2 | 未获取到body元素 |
3 | 未获取到selector 对应DOM元素 |
4 | 未选中任何文件 |
5 | 调用方法reCrop() 时,未获取到之前的文件数据 |
7 | 处理的file非图片或视频文件 |
8 | 读取file文件数据出错 |
11 | 预加载图片数据出错 |
12 | 文件太大,超过了最大限制 |
13 | 视频截图失败,视频资源可能不在同域中 |
21 | 图片手动裁剪,设置预览图片src失败 |
22 | 用户取消了手动裁剪 |
Code and documentation copyright 2018. capricorncd. Code released under the MIT License.
FAQs
A Image clipping or scaling, support local or same domain video file screenshot. It's implemented in canvas.
The npm package image-process receives a total of 32 weekly downloads. As such, image-process popularity was classified as not popular.
We found that image-process demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.