1.0.4 • Published 3 years ago

resize-imagejs v1.0.4

Weekly downloads
-
License
MIT
Repository
-
Last release
3 years ago

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>