{"id":39489066,"url":"https://github.com/ranjandsingh/sharp-multer","last_synced_at":"2026-01-18T05:30:47.810Z","repository":{"id":54600705,"uuid":"497118011","full_name":"ranjandsingh/sharp-multer","owner":"ranjandsingh","description":" Utility package  to use with Multer as storage engine to optimise images on the fly It uses Sharp to optimise images to jpg, png, webp as well as resize them.","archived":false,"fork":false,"pushed_at":"2024-11-22T20:02:06.000Z","size":23,"stargazers_count":11,"open_issues_count":1,"forks_count":3,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-08-09T15:56:06.372Z","etag":null,"topics":["express","image-crop","image-optimisation","image-optimization","image-processing","multer","node-images","node-imageserver","nodejs","sharp"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/sharp-multer","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ranjandsingh.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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":"2022-05-27T19:41:04.000Z","updated_at":"2024-12-30T08:10:51.000Z","dependencies_parsed_at":"2024-05-31T18:14:05.998Z","dependency_job_id":null,"html_url":"https://github.com/ranjandsingh/sharp-multer","commit_stats":{"total_commits":17,"total_committers":3,"mean_commits":5.666666666666667,"dds":"0.11764705882352944","last_synced_commit":"1afdc05643c254c632f9db97ec5abec127b989c7"},"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/ranjandsingh/sharp-multer","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ranjandsingh%2Fsharp-multer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ranjandsingh%2Fsharp-multer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ranjandsingh%2Fsharp-multer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ranjandsingh%2Fsharp-multer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ranjandsingh","download_url":"https://codeload.github.com/ranjandsingh/sharp-multer/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ranjandsingh%2Fsharp-multer/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28530845,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-18T00:39:45.795Z","status":"online","status_checked_at":"2026-01-18T02:00:07.578Z","response_time":98,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["express","image-crop","image-optimisation","image-optimization","image-processing","multer","node-images","node-imageserver","nodejs","sharp"],"created_at":"2026-01-18T05:30:47.255Z","updated_at":"2026-01-18T05:30:47.604Z","avatar_url":"https://github.com/ranjandsingh.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Sharp-Multer\n\nSmall Utility to use with Multer as storage engine to optimize images on the fly It uses Sharp to optimize images to jpg, png, webp as well as resize them.\n\n## Install\n\n\u003e `npm install sharp-multer`\n\n## Example\n\n```js\nconst multer = require(\"multer\");\n\nconst SharpMulter = require(\"sharp-multer\");\nconst app = express();\n\n// optional function to return new File Name\nconst newFilenameFunction = (og_filename, options) =\u003e {\n  const newname =\n    og_filename.split(\".\").slice(0, -1).join(\".\") +\n    `${options.useTimestamp ? \"-\" + Date.now() : \"\"}` +\n    \".\" +\n    options.fileFormat;\n  return newname;\n};\n\nconst storage = SharpMulter({\n  destination: (req, file, callback) =\u003e callback(null, \"images\"),\n\n  imageOptions: {\n    fileFormat: \"png\",\n    quality: 80,\n    resize: { width: 500, height: 500, resizeMode: \"contain\" },\n  },\n\n  watermarkOptions: {\n    input: \"./images/logo.png\",\n    location: \"top-right\",\n  },\n  filename: newFilenameFunction, // optional\n});\nconst upload = multer({ storage });\napp.post(\"/upload\", upload.single(\"avatar\"), async (req, res) =\u003e {\n  console.log(req.file);\n\n  return res.json(\"File Uploaded Successfully!\");\n});\n```\n\n## Image Options\n\n| Key              | Option                                                     | Description                                                                                                                                                        |\n| ---------------- | ---------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------ |\n| fileFormat       | `jpg / png/ webp 'Default:\"jpg\"`                           | Output file type                                                                                                                                                   |\n| resize           | `{height:\"\", widht:\"\",resizeMode:\"\", withoutEnlargement: true/false } 'Default:{}'`        | If provided Images will be resized before saving                                                                                                                  |\n| quality          | `Number(0-100) 'Default :80'`                              | Reduces the qulity for better performance                                                                                                                          |\n| useTimestamp     | `true/false 'Default :false'`(optional)                    | Adds suffice to file name Ex: \"Images_1653679779.jpg\"                                                                                                              |\n| watermarkOptions | `{input:\"\", location:\"\",opacity:1-100}` (optional)        | Adds watermark on every Images before Saving                                                                                                                       |\n| filename         | `(originalname,options,req) =\u003e return newname` (optional) | Option to return a new name for saving file it will give you original name as first argument you must return a string with filename and extension like \"image.png\" |\n\n### resizeMode\n\n\u003e resize.resizeMode\n\n- `cover`: (default) Preserving aspect ratio, ensure the image covers both provided dimensions by cropping/clipping to fit.\n- `contain`: Preserving aspect ratio, contain within both provided dimensions using \"letterboxing\" where necessary.\n- `fill`: Ignore the aspect ratio of the input and stretch to both provided dimensions. _i.e images will be starched to match size provided_\n- `inside`: Preserving aspect ratio, resize the image to be as large as possible while ensuring its dimensions are less than or equal to both those specified. _i.e width will be fixed to max value you provide and height will be adjusted to a lower value than provided according to Aspect Ratio_ .\n- `outside`: Preserving aspect ratio, resize the image to be as small as possible while ensuring its dimensions are greater than or equal to both those specified. _i.e height will be fixed to value you provide and width will be adjusted to a higher value than provided according to Aspect Ratio_\n\n### withoutEnlargement\n\n\u003e resize.withoutEnlargement\n\nIf ```withoutEnlargement``` is true, image to be resized is smaller than selected size, resize operation will not be performed.\n\n### location\n\n\u003e watermarkOptions.location\n\nwatermarkOptions supports total 5 locations : `\"center\",\"top-left\",\"top-right\",\"bottom-left\",\"bottom-right\"`\n\n### filename\n\nOption to return a new name for saving file it will give you original name as first argument you must return a string with filename and extension like \"image.png\"\nex:\n\n```js\nconst newFilenameFunction = (og_filename, options) =\u003e {\n  const newname =\n    og_filename.split(\".\").slice(0, -1).join(\".\") +\n    `${options.useTimestamp ? \"-\" + Date.now() : \"\"}` +\n    \".\" +\n    options.fileFormat;\n  return newname;\n};\n```\n\nIf you want to use a request field called `metadata` passed in the body to generate the filename, you can do it like this:\n\n```js\nconst newFilenameFunction = (og_filename, options, req) =\u003e {\n  return `${og_filename}_${req.body.metadata}.${options.fileFormat}`;\n};\n```\n\nNote that any other field present in the request body will work.\n\nFeel free to open a Issue for features or bug fixes\n\nThanks\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Franjandsingh%2Fsharp-multer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Franjandsingh%2Fsharp-multer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Franjandsingh%2Fsharp-multer/lists"}