{"id":21297292,"url":"https://github.com/voidberg/imagecache-sharp","last_synced_at":"2025-07-11T18:32:28.693Z","repository":{"id":21813840,"uuid":"94096535","full_name":"voidberg/imagecache-sharp","owner":"voidberg","description":"Image processing library based on sharp and inspired by Drupal's image styles.","archived":false,"fork":false,"pushed_at":"2024-06-18T19:16:50.000Z","size":21754,"stargazers_count":2,"open_issues_count":2,"forks_count":1,"subscribers_count":5,"default_branch":"main","last_synced_at":"2025-07-01T12:09:55.672Z","etag":null,"topics":["crop","image","image-processing","imagecache","resize","sharp","thumbnail-generator","thumbnails","typescript"],"latest_commit_sha":null,"homepage":"http://alexandrubadiu.ro/imagecache-sharp/","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/voidberg.png","metadata":{"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":"2017-06-12T12:59:45.000Z","updated_at":"2023-04-28T10:56:29.000Z","dependencies_parsed_at":"2024-11-21T14:47:23.088Z","dependency_job_id":null,"html_url":"https://github.com/voidberg/imagecache-sharp","commit_stats":{"total_commits":99,"total_committers":4,"mean_commits":24.75,"dds":"0.43434343434343436","last_synced_commit":"168b358ddda1a71e307dcb75e3d08ceeaf978d2b"},"previous_names":[],"tags_count":15,"template":false,"template_full_name":null,"purl":"pkg:github/voidberg/imagecache-sharp","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/voidberg%2Fimagecache-sharp","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/voidberg%2Fimagecache-sharp/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/voidberg%2Fimagecache-sharp/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/voidberg%2Fimagecache-sharp/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/voidberg","download_url":"https://codeload.github.com/voidberg/imagecache-sharp/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/voidberg%2Fimagecache-sharp/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":264870566,"owners_count":23676267,"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":["crop","image","image-processing","imagecache","resize","sharp","thumbnail-generator","thumbnails","typescript"],"created_at":"2024-11-21T14:35:15.910Z","updated_at":"2025-07-11T18:32:23.682Z","avatar_url":"https://github.com/voidberg.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Latest release on NPM](https://img.shields.io/npm/v/imagecache-sharp.svg)](https://www.npmjs.com/package/imagecache-sharp)\n[![npm module downloads per month](http://img.shields.io/npm/dm/imagecache-sharp.svg?style=flat)](https://www.npmjs.org/package/imagecache-sharp)\n[![Build states](https://github.com/voidberg/imagecache-sharp/workflows/CI/badge.svg)](https://github.com/voidberg/imagecache-sharp/actions?query=workflow%3A%22CI%22+branch%3Amaster++)\n[![Codecov](https://img.shields.io/codecov/c/gh/voidberg/imagecache-sharp)](https://codecov.io/github/voidberg/imagecache-sharp)\n[![Semantic release](https://img.shields.io/badge/semantic--release-angular-e10079?logo=semantic-release)](https://github.com/semantic-release/semantic-release/)\n[![Commitizen friendly](https://img.shields.io/badge/commitizen-friendly-brightgreen.svg)](http://commitizen.github.io/cz-cli/)\n[![Apache 2.0 License](https://img.shields.io/npm/l/imagecache-sharp.svg)](https://opensource.org/licenses/Apache-2.0)\n\n![ImageCache Sharp](https://www.dropbox.com/s/7nedtm45o1d46k5/imagecache-small.png?raw=1)\n\n## What is it?\n\nImagecache Sharp is a node image processing library based on [sharp](https://github.com/lovell/sharp) that allows you to create presets based on a list of chained actions, such as resizing, applying a watermark, or applying various image operations (blur, flip, negate, etc).\n\nIt was inspired by Drupal's [imagecache module](https://www.drupal.org/project/imagecache) (now called image styles), hence the name.\n\n\u003ca href=\"https://www.dropbox.com/s/nhwzy0utvw2m0qe/imagecache-details.png?raw=1\" target=\"_blank\"\u003e\u003cimg src=\"https://www.dropbox.com/s/nhwzy0utvw2m0qe/imagecache-details.png?raw=1\" alt=\"Imagecache workflow\" width=\"100%\" /\u003e\u003c/a\u003e\n\n## Installation\n\n- `npm install imagecache-sharp`\n\n## Usage\n\n```typescript\nimport { ImageCache, Image } from \"../src/imagecache\";\nimport presets from \"./presets\";\n\nconst imagecache: ImageCache = new ImageCache(presets);\n\nconst image: Image = await imagecache.render(\n  \"./in.png\",\n  \"canvas_scale_with_blur\"\n);\n\n// Save the image\nawait image.toFile(\"out_canvas_scale_with_blur.png\");\n\n// Get a buffer, stream it etc\nimage.toBuffer(...)\n```\n\nThe render function returns a `sharp.Sharp` instance (`Image` is just an alias for it) which can be used in various ways for outputting the final image. For a list of options see [sharp's documentation](https://sharp.pixelplumbing.com/api-constructor).\n\n## Presets structure\n\nA preset is defined like this:\n\n```typescript\ntype Preset = {\n  presetName: string;\n  actions: Action[];\n};\n```\n\nAn action contains an operation (which is defined by the plugins) and an optional config.\n\n```typescript\ntype Action = {\n  action: string;\n  config?: any;\n};\n```\n\nHere are two example presets. The first one resizes and crops the image, puts it on a bigger canvas, then blurs it. The second one resizes and crops the image.\n\n```typescript\n{\n  presetName: 'canvas_scale_with_blur',\n  actions: [\n    {\n      action: 'scale_and_crop',\n      config: {\n        width: 152,\n        height: 152,\n      },\n    },\n    {\n      action: 'define_canvas',\n      config: {\n        color: '#333333',\n        width: 400,\n        height: 400,\n      },\n    },\n    {\n      action: 'blur',\n    },\n  ],\n},\n```\n\n```typescript\n{\n  presetName: 'scale_crop_tiny',\n  actions: [\n    {\n      action: 'scale_and_crop',\n      config: {\n        width: 32,\n        height: 32,\n      },\n    },\n  ],\n},\n```\n\n## Imagecache actions:\n\n### Blur\n\nBlurs the image.\n\nAction name: `blur`.\n\nConfiguration:\n\n- `sigma`: A value between 0.3 and 1000 representing the sigma of the Gaussian mask. Defaults to `50`.\n\n### Define canvas\n\nDefines a new canvas and overlays the current image.\n\nAction name: `define_canvas`.\n\nConfiguration:\n\n- `width`: The width of the canvas.\n- `height`: The height of the canvas.\n- `channels`: Number of channels. Defaults to `4`.\n- `background`: The background colour of the canvas in hex format.\n\n### File\n\nLoads an image and overlays it on the current image.\n\nAction name: `file`.\n\nConfiguration:\n\n- `path`: The path of the file.\n- `gravity`: Gravity at which to place the overlay. Possible values are `north`, `northeast`, `east`, `southeast`, `south`, `southwest`, `west`, `northwest`, `center` and `centre`. Defaults to `center`.\n- `tile`: Set to true to repeat the overlay image across the entire image with the given `gravity`. Defaults to `false`.\n\n### Flip\n\nFlips the image on a given axis.\n\nAction name: `flip`.\n\nConfiguration:\n\n- `axis`: The axis to flip on. Defaults to `y`.\n\n### Gamma\n\nApply a gamma correction to the image.\n\nAction name: `gamma`.\n\nConfiguration:\n\n- `gamma`: Value between 1.0 and 3.0. Defaults to `2.2`.\n\n### Greyscale\n\nConvert to 8-bit greyscale, 256 shades of grey.\n\nAction name: `greyscale`.\n\n### Negate\n\nProduce the \"negative\" of the image.\n\nAction name: `negate`.\n\n### Normalize\n\nEnhance output image contrast by stretching its luminance to cover the full dynamic range.\n\nAction name: `normalize`.\n\n### Rotate\n\nRotates the image based on the EXIF data or at a specified angle.\n\nAction name: `rotate`.\n\nConfiguration:\n\n- `angle`: Angle, multiple of 90. Defaults to `auto` which uses EXIF.\n\n### Scale\n\nScales the image ignoring the aspect ratio.\n\nAction name: `scale`.\n\nConfiguration:\n\n- `width`: The width of the new image. Can be a number or a percent value.\n- `height`: The height of the new image. Can be a number or a percent value.\n- `upscale`: Whether to upscale the image. Defaults to true.\n\n### Scale and crop\n\nScales and crops the image maintaining the aspect ratio.\n\nAction name: `scale_and_crop`.\n\nConfiguration:\n\n- `width`: The width of the new image. Can be a number or a percent value.\n- `height`: The height of the new image. Can be a number or a percent value.\n- `gravity`: Where to crop from. Possible values are `north`, `northeast`, `east`, `southeast`, `south`, `southwest`, `west`, `northwest`, `center` and `centre`. Defaults to `center`.\n\n### Sharpen\n\nSharpen the image.\n\nAction name: `sharpen`.\n\nConfiguration:\n\n- `sigma`: The sigma of the Gaussian mask. Defaults to `1`.\n- `flat`: The level of sharpening to apply to \"flat\" areas. Defaults to `1.0`.\n- `jagged`: The level of sharpening to apply to \"jagged\" areas. Defaults to `2.0`.\n\n## Thanks to:\n\n- [Smashicons - Flaticon](https://www.flaticon.com/free-icons/image-editing) for the logo.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvoidberg%2Fimagecache-sharp","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvoidberg%2Fimagecache-sharp","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvoidberg%2Fimagecache-sharp/lists"}