{"id":15662899,"url":"https://github.com/azu/validate-image-type","last_synced_at":"2025-05-05T21:43:17.191Z","repository":{"id":48518974,"uuid":"265996576","full_name":"azu/validate-image-type","owner":"azu","description":"Check the image file of a Buffer/Uint8Array that matched expected image MIME-type.","archived":false,"fork":false,"pushed_at":"2023-10-22T11:35:48.000Z","size":159,"stargazers_count":18,"open_issues_count":0,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-31T00:01:34.464Z","etag":null,"topics":["bufffer","extension","image","jpg","mime-type","png","svg","valicator","validate"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/azu.png","metadata":{"funding":{"github":"azu"},"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-05-22T02:09:09.000Z","updated_at":"2024-04-30T02:25:03.000Z","dependencies_parsed_at":"2024-10-23T08:25:32.953Z","dependency_job_id":"886553b7-26c5-401d-a2ef-862ce72a38ee","html_url":"https://github.com/azu/validate-image-type","commit_stats":{"total_commits":22,"total_committers":3,"mean_commits":7.333333333333333,"dds":"0.18181818181818177","last_synced_commit":"c1f4d7e99564adcd852e399abac6b87700be4606"},"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/azu%2Fvalidate-image-type","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/azu%2Fvalidate-image-type/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/azu%2Fvalidate-image-type/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/azu%2Fvalidate-image-type/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/azu","download_url":"https://codeload.github.com/azu/validate-image-type/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252582242,"owners_count":21771634,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bufffer","extension","image","jpg","mime-type","png","svg","valicator","validate"],"created_at":"2024-10-03T13:34:52.257Z","updated_at":"2025-05-05T21:43:17.171Z","avatar_url":"https://github.com/azu.png","language":"TypeScript","readme":"# validate-image-type [![Actions Status](https://github.com/azu/validate-image-type/workflows/test/badge.svg)](https://github.com/azu/validate-image-type/actions?query=workflow%3A\"test\")\n\nCheck the image file of a Buffer/Uint8Array that matched expected image MIME-type.\n\nThis library check the **file contents** instead of **file extensions** using following:\n\n- [sindresorhus/file-type: Detect the file type of a Buffer/Uint8Array/ArrayBuffer](https://github.com/sindresorhus/file-type)\n- [sindresorhus/is-svg: Check if a string or buffer is SVG](https://github.com/sindresorhus/is-svg)\n\n## Features\n\n- Support various image types: [popular images types](https://github.com/sindresorhus/image-type#supported-file-types) + SVG\n- Reject File Camouflage by checking actual content buffer\n\n## Install\n\nInstall with [npm](https://www.npmjs.com/):\n\n    npm install validate-image-type\n\n## Usage\n\n```ts\nimport { validateMIMEType } from \"validate-image-type\";\nconst result = await validateMIMEType(\"./image.png\", {\n    allowMimeTypes: ['image/jpeg', 'image/gif', 'image/png', 'image/svg+xml']\n});\nif (!result.ok) {\n    console.error(result.error);\n    return;\n}\nconsole.log(\"This image is supported!\");\n```\n\nSee following document about MimeType.\n\n- https://developer.mozilla.org/docs/Web/HTTP/Basics_of_HTTP/MIME_types\n\n## Supported file types \n\nBasic images file types and SVG(`image/svg+xml`).\n\n    \"jpg\",\n    \"png\",\n    \"gif\",\n    \"webp\",\n    \"flif\",\n    \"cr2\",\n    \"tif\",\n    \"bmp\",\n    \"jxr\",\n    \"psd\",\n    \"ico\",\n    \"bpg\",\n    \"jp2\",\n    \"jpm\",\n    \"jpx\",\n    \"heic\",\n    \"cur\",\n    \"dcm\",\n    \"svg\"\n\n\n## Examples\n\nIntegration with [Multer](https://github.com/expressjs/multer) middleware.\n\n```js\nconst multer = require('multer');\nconst temp_local_img_dir = path.join(__dirname, `/.temp_local_img_dir`);\nconst upload = multer({ dest: temp_local_img_dir });\nconst asyncWrapper = fn =\u003e {\n    return (req, res, next) =\u003e {\n        return fn(req, res, next).catch(next);\n    }\n};\n\napp.post(\n  '/upload',\n  upload.single('image'), \n  asyncWrapper(async (req, res, next) =\u003e {\n    const validationResult = await validateMIMEType(req.file.path, {\n      originalFilename: req.file.originalname,\n      allowMimeTypes: ['image/jpeg', 'image/gif', 'image/png', 'image/svg+xml'],\n    });\n    console.log('validationResult', validationResult);\n    if (!validationResult.ok) {\n      return res.send(400);\n    }\n    // uploading task\n    // ...\n  })\n);\n```\n\n## Changelog\n\nSee [Releases page](https://github.com/azu/validate-image-type/releases).\n\n## Running tests\n\nInstall devDependencies and Run `npm test`:\n\n    npm test\n\n## Contributing\n\nPull requests and stars are always welcome.\n\nFor bugs and feature requests, [please create an issue](https://github.com/azu/validate-image-type/issues).\n\n1. Fork it!\n2. Create your feature branch: `git checkout -b my-new-feature`\n3. Commit your changes: `git commit -am 'Add some feature'`\n4. Push to the branch: `git push origin my-new-feature`\n5. Submit a pull request :D\n\n## Author\n\n- [github/azu](https://github.com/azu)\n- [twitter/azu_re](https://twitter.com/azu_re)\n\n## License\n\nMIT © azu\n","funding_links":["https://github.com/sponsors/azu"],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fazu%2Fvalidate-image-type","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fazu%2Fvalidate-image-type","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fazu%2Fvalidate-image-type/lists"}