https://github.com/chickencoding123/image-validation
Image validation utility for DOM and Node.js beyond the file extensions
https://github.com/chickencoding123/image-validation
Last synced: about 2 months ago
JSON representation
Image validation utility for DOM and Node.js beyond the file extensions
- Host: GitHub
- URL: https://github.com/chickencoding123/image-validation
- Owner: chickencoding123
- License: mit
- Created: 2022-05-12T12:36:27.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2022-05-14T21:30:02.000Z (almost 3 years ago)
- Last Synced: 2025-01-22T05:43:12.687Z (3 months ago)
- Language: TypeScript
- Size: 170 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
image-validation
======Image validation utility for DOM and Node.js beyond the file extensions
[](https://www.npmjs.com/package/image-validation) [](https://github.com/chickencoding123/image-validation/blob/main/LICENSE)
## Features
- Validate images in various input formats
- Validate based on image data instead of file extension
- Runs in browser or [node.js](https://nodejs.org)
- Graceful mode (optional) for failed images
- Comes with CLI## How to use
```sh
npm i image-validation
# or
yarn add image-validation
``````js
const imageValidation = require('image-validation').default
// or
const { default: imageValidation } = require('image-validation')
// or
import ImageValidation from 'image-validation'
```
Very simple to run:
```js
// then
ImageValidation('image base64 string, arrays, buffer etc...')
.then(result => {
// result is either true or false
})
// or
const result = await ImageValidation('image base64 string, arrays, buffer etc...')
```## Configure throwing error or returning false
By default the validation will throw an error for an invalid/corrupt image, but this can be changed to return `false` and fail gracefully.
```js
const result = await ImageValidation('image base64 string, arrays, buffer etc...', { throw: false })
```## Why?
Allows you to detect image corruption automatically which is very useful in workflows. Technically the image corruption must be fixed at source, but this is not always a possibility. In the future I'd like to add security scanning for metadata exploits and such.