{"id":16721183,"url":"https://github.com/khalyomede/gulp-sharp-responsive","last_synced_at":"2025-04-10T10:05:12.483Z","repository":{"id":41166126,"uuid":"359154137","full_name":"khalyomede/gulp-sharp-responsive","owner":"khalyomede","description":"A gulp plugin to generate responsives images.","archived":false,"fork":false,"pushed_at":"2023-05-27T10:04:00.000Z","size":1179,"stargazers_count":17,"open_issues_count":7,"forks_count":5,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-02T01:35:15.747Z","etag":null,"topics":["avif","gulp","gulpplugin","image-processing","responsive","sharp","webp"],"latest_commit_sha":null,"homepage":"https://npmjs.com/package/gulp-sharp-responsive","language":"TypeScript","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/khalyomede.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-04-18T13:42:31.000Z","updated_at":"2024-04-22T10:17:16.000Z","dependencies_parsed_at":"2022-07-25T21:32:20.268Z","dependency_job_id":null,"html_url":"https://github.com/khalyomede/gulp-sharp-responsive","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/khalyomede%2Fgulp-sharp-responsive","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/khalyomede%2Fgulp-sharp-responsive/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/khalyomede%2Fgulp-sharp-responsive/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/khalyomede%2Fgulp-sharp-responsive/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/khalyomede","download_url":"https://codeload.github.com/khalyomede/gulp-sharp-responsive/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248198879,"owners_count":21063628,"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":["avif","gulp","gulpplugin","image-processing","responsive","sharp","webp"],"created_at":"2024-10-12T22:29:13.050Z","updated_at":"2025-04-10T10:05:12.459Z","avatar_url":"https://github.com/khalyomede.png","language":"TypeScript","readme":"# gulp-sharp-responsive\r\n\r\nA gulp plugin to generate responsives images.\r\n\r\n[![Build Status](https://travis-ci.com/khalyomede/gulp-sharp-responsive.svg?branch=master)](https://travis-ci.com/khalyomede/gulp-sharp-responsive) [![npm](https://img.shields.io/npm/v/gulp-sharp-responsive)](https://www.npmjs.com/package/gulp-sharp-responsive) ![NPM](https://img.shields.io/npm/l/gulp-sharp-responsive)\r\n\r\n## Summary\r\n\r\n- [About](#about)\r\n- [Features](#features)\r\n- [Installation](#installation)\r\n- [Examples](#examples)\r\n- [Options](#options)\r\n- [Test](#test)\r\n\r\n## About\r\n\r\nI make web apps and I often need to generate images of multi formats and size from a single image. For example, an image \"lion.jpeg\", that is declined like this:\r\n\r\n- lion-sm.jpeg\r\n- lion-sm.webp\r\n- lion-sm.avif\r\n- lion-lg.jpeg\r\n- lion-lg.webp\r\n- lion-lg.avif\r\n\r\nSharp can do this, and since I use Gulp for my everyday tasks, I created a plugin to automatize this task.\r\n\r\n## Features\r\n\r\n- Based on [Sharp](https://github.com/lovell/sharp)\r\n- Takes options to generate images by sizes and format\r\n- Supports theses formats:\r\n  - jpeg\r\n  - png\r\n  - gif\r\n  - webp\r\n  - avif\r\n  - heif\r\n  - tiff\r\n- Can pass Sharp specific options to customize even more the image generation\r\n- Written in TypeScript, so you get type hints for the options\r\n\r\n## Installation\r\n\r\nIn your terminal:\r\n\r\n```bash\r\nnpm install --save-dev gulp-sharp-responsive\r\n```\r\n\r\nWith Yarn:\r\n\r\n```bash\r\nyarn add --dev gulp-sharp-responsive\r\n```\r\n\r\n## Examples\r\n\r\nSidenote: all the following example uses the TS version of gulpfile. This is why you will see ES6 syntaxes like \"import ...\".\r\n\r\nIf you are using the \"classic\" syntax (require), just convert the ES6 to CommonJS like following:\r\n\r\n```js\r\n// this\r\nimport { src, dest } from \"gulp\";\r\nimport sharpResponsive from \"gulp-sharp-responsive\";\r\n\r\n// becomes this\r\nconst { src, dest } = require(\"gulp\");\r\nconst sharpResponsive = require(\"gulp-sharp-responsive\");\r\n```\r\n\r\nNote that if you are using typescript, don't forget to add the \"esModuleInterop\" option to true in you `tsconfig.json` in order for the ES6 syntax mentioned above to work.\r\n\r\n```json\r\n{\r\n  \"compilerOptions\": {\r\n    \"esModuleInterop\": true\r\n  }\r\n}\r\n```\r\n\r\n- [1. Generate image of different sizes](#1-generate-image-of-different-sizes)\r\n- [2. Generate image of different formats](#2-generate-image-of-different-formats)\r\n- [3. Include the original file in the output images](#3-include-the-original-file-in-the-output-images)\r\n- [4. Pass format specific options](#4-pass-format-specific-options)\r\n- [5. Pass sharp specific options](#5-pass-sharp-specific-options)\r\n- [6. Use a callback to compute the width](#6-use-a-callback-to-compute-the-width)\r\n\r\n### 1. Generate image of different sizes\r\n\r\nIn this example, we will generate a small and large image size from an image.\r\n\r\n```typescript\r\nimport { src, dest } from \"gulp\";\r\nimport sharpResponsive from \"gulp-sharp-responsive\";\r\n\r\nconst img = () =\u003e src(\"src/img/**/*.{jpg,png}\")\r\n  .pipe(sharpResponsive({\r\n    formats: [\r\n      { width: 640, rename: { suffix: \"-sm\" } },\r\n      { width: 1024, rename: { suffix: \"-lg\" } },\r\n    ]\r\n  }))\r\n  .pipe(dest(\"dist/img\"));\r\n```\r\n\r\n### 2. Generate image of different formats\r\n\r\nIn this example, we will generate modern image format like webp and avif from an image.\r\n\r\n```typescript\r\nimport { src, dest } from \"gulp\";\r\nimport sharpResponsive from \"gulp-sharp-responsive\";\r\n\r\nconst img = () =\u003e src(\"src/img/**/*.{jpg,png}\")\r\n  .pipe(sharpResponsive({\r\n    formats: [\r\n      { width: 640, format: \"webp\" },\r\n      { width: 640, format: \"avif\" },\r\n    ]\r\n  }))\r\n  .pipe(dest(\"dist/img\"));\r\n```\r\n\r\n### 3. Include the original file in the output images\r\n\r\nIn this example, we will tell the plugin to keep the original file to be outputed in the dist folder.\r\n\r\n```typescript\r\nimport { src, dest } from \"gulp\";\r\nimport sharpResponsive from \"gulp-sharp-responsive\";\r\n\r\nconst img = () =\u003e src(\"src/img/**/*.{jpg,png}\")\r\n  .pipe(sharpResponsive({\r\n    includeOriginalFile: true,\r\n  }))\r\n  .pipe(dest(\"dist/img\"));\r\n```\r\n\r\n### 4. Pass format specific options\r\n\r\nIn this example, we will use JPEG options to customize how we want our image to be generated.\r\n\r\n```typescript\r\nimport { src, dest } from \"gulp\";\r\nimport sharpResponsive from \"gulp-sharp-responsive\";\r\n\r\nconst img = () =\u003e src(\"src/img/**/*.{jpg,png}\")\r\n  .pipe(sharpResponsive({\r\n    formats: [\r\n      { width: 640, jpegOptions: { quality: 60, progressive: true } }\r\n    ],\r\n  }))\r\n  .pipe(dest(\"dist/img\"));\r\n```\r\n\r\nYou can pass options for various formats. Here is all supported options and their documentation:\r\n\r\n- [jpegOptions](https://sharp.pixelplumbing.com/api-output#jpeg)\r\n- [pngOptions](https://sharp.pixelplumbing.com/api-output#png)\r\n- [webpOptions](https://sharp.pixelplumbing.com/api-output#webp)\r\n- [gifOptions](https://sharp.pixelplumbing.com/api-output#gif)\r\n- [tiffOptions](https://sharp.pixelplumbing.com/api-output#tiff)\r\n- [avifOptions](https://sharp.pixelplumbing.com/api-output#avif)\r\n- [heifOptions](https://sharp.pixelplumbing.com/api-output#heif)\r\n\r\n### 5. Pass sharp specific options\r\n\r\nIn this example, we will pass Sharp options to customize its behavior.\r\n\r\n```typescript\r\nimport { src, dest } from \"gulp\";\r\nimport sharpResponsive from \"gulp-sharp-responsive\";\r\n\r\nconst img = () =\u003e src(\"src/img/**/*.{jpg,png}\")\r\n  .pipe(sharpResponsive({\r\n    formats: [\r\n      { width: 640, sharp: { failOnError: false, density: 340 } }\r\n    ],\r\n  }))\r\n  .pipe(dest(\"dist/img\"));\r\n```\r\n\r\nFind all the available options in the [Sharp constructor documentation](https://sharp.pixelplumbing.com/api-constructor#sharp).\r\n\r\n### 6. Use a callback to compute the width\r\n\r\nIn this example, we will use the file metadata to compute the width dynamically.\r\n\r\n```typescript\r\nimport { src, dest } from \"gulp\";\r\nimport sharpResponsive from \"gulp-sharp-responsive\";\r\n\r\nconst img = () =\u003e src(\"src/img/**/*.{jpg,png}\")\r\n  .pipe(sharpResponsive({\r\n    formats: [\r\n      { width: (metadata) =\u003e metadata.width * 0.5 } // divides the original image width by 2\r\n    ]\r\n  }))\r\n  .pipe(dest(\"dist/img\"));\r\n```\r\n\r\n## Options\r\n\r\n- [formats](#formats)\r\n- [includeOriginalFile](#includeoriginalfile)\r\n- [IFileMetadata](#ifilemetadata)\r\n\r\n### formats\r\n\r\nA list of transformations to operate on the file.\r\n\r\n```typescript\r\nformat: [\r\n  {\r\n    width: number | ((metadata IFileMetadata) =\u003e number),\r\n    format?: \"jpeg\" | \"png\" | \"webp\" | \"gif\" | \"tiff\" | \"avif\" | \"heif\",\r\n    rename?: {\r\n      dirname?: string,\r\n      prefix?: string,\r\n      basename?: string,\r\n      suffix?: string,\r\n      extname?: string,\r\n    },\r\n    sharp?: {\r\n      // ...\r\n    },\r\n    jpegOptions?: {\r\n      // ...\r\n    },\r\n    pngOptions?: {\r\n      // ...\r\n    },\r\n    webpOptions?: {\r\n      // ...\r\n    },\r\n    gifOptions?: {\r\n      // ...\r\n    },\r\n    tiffOptions?: {\r\n      // ...\r\n    },\r\n    avifOptions?: {\r\n      // ...\r\n    },\r\n    heifOptions?: {\r\n      // ...\r\n    },\r\n  },\r\n];\r\n```\r\n\r\n### includeOriginalFile\r\n\r\nWether to include the original transformed file in the output or not. Default to false (not included).\r\n\r\n```typescript\r\nincludeOriginalFile?: boolean,\r\n```\r\n\r\n### IFileMetadata\r\n\r\n```typescript\r\ninterface IFileMetadata {\r\n  width: number;\r\n  height: number;\r\n}\r\n```\r\n\r\n## Test\r\n\r\n```bash\r\nnpm run test\r\n```\r\n\r\n## Publish\r\n\r\nFirst make sure the version in `package.json` is the version to publish.\r\n\r\n```bash\r\nnpm login\r\nnpm publish\r\n```\r\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkhalyomede%2Fgulp-sharp-responsive","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkhalyomede%2Fgulp-sharp-responsive","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkhalyomede%2Fgulp-sharp-responsive/lists"}