Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

resize-imagejs

zhousuyang29MIT1.0.4TypeScript support: included

Resize Image And Convert image to Base64 Or Blob

Front Web, Resize Image, Image, Convert Image To Base64 Or Blob, Image Base64, Image Blob

readme

Resize Image And Convert image to Base64 Or Blob

resizeImage(file, options)

file -> image

  • options (Object)
    • width: optional [number]
    • height: optional [number]
    • type: default: 'blob', optional: 'base64'、'blob'
import resizeImage from 'resize-imagejs'

handleClassFileChange = e => {
  const file = e.target.files[0]
  if (file) {
    resizeImage(file, { width: 200, height: 200, type: 'blob' }).then(blob => {
      const fd = new FormData()
      fd.append('file', blob)
      ...
    })
  }
}


<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <script src="./dist/resize-imagejs.umd.js"></script>
</head>
<body>
  <script>
    console.log(window.resizeImagejs)
  </script>
</body>
</html>