1.0.3 • Published 6 months ago

bisect-image-to-files v1.0.3

Weekly downloads
-
License
ISC
Repository
github
Last release
6 months ago

bisect-image-to-files

中文 / English

中文

本库适用于需要将上传的图片从中间一分为二进行裁切处理后再上传的场景。

借助 canvas 实现将图片从中间一分为左右两半,各自生成新的 File 对象,放入数组中返回。

安装

npm install bisect-image-to-files
# 或
pnpm add bisect-image-to-files

使用

将获取到的图片 File 对象 file 传入 bisectImageToFiles() 即可,方法返回结果为一数组,数组里是被截为左右 2 半的图片各自生成的 File 对象。

import bisectImageToFiles from 'bisect-image-to-files'
const fileInput = document.createElement('input')
fileInput.type = 'file'
fileInput.accept = 'image/*'
fileInput.onchange = async event => {
  const file = event.target.files[0]
  if (file) {
    const files = await bisectImageToFiles(file)
    console.log(files)
  }
}
document.body.appendChild(fileInput)

English

This library is suitable for scenarios where uploaded images need to be split in half and cropped before uploading.

Usage

Simply pass the obtained image File object file into bisectImageToFiles(), and the method will return an array containing the File objects generated by each image that has been truncated into two halves.

1.0.3

6 months ago

1.0.2

6 months ago

1.0.1

6 months ago

1.0.0

6 months ago