{"id":15593271,"url":"https://github.com/derhuerst/gulp-scale-images","last_synced_at":"2025-04-15T05:36:48.818Z","repository":{"id":30875134,"uuid":"126258869","full_name":"derhuerst/gulp-scale-images","owner":"derhuerst","description":"Gulp plugin to resize each image into multiple smaller variants.","archived":false,"fork":false,"pushed_at":"2024-02-22T15:33:25.000Z","size":601,"stargazers_count":13,"open_issues_count":4,"forks_count":5,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-15T05:36:42.662Z","etag":null,"topics":["gulp","gulp-plugin","image","picture","resize","scale","sharp"],"latest_commit_sha":null,"homepage":"https://github.com/derhuerst/gulp-scale-images#gulp-scale-images","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"isc","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/derhuerst.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":"license.md","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":"2018-03-22T00:52:37.000Z","updated_at":"2024-09-07T00:21:17.000Z","dependencies_parsed_at":"2024-02-22T16:53:37.946Z","dependency_job_id":null,"html_url":"https://github.com/derhuerst/gulp-scale-images","commit_stats":{"total_commits":61,"total_committers":8,"mean_commits":7.625,"dds":0.3278688524590164,"last_synced_commit":"98fed719bfc41023e73c5d637774d0615c1c201b"},"previous_names":[],"tags_count":17,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/derhuerst%2Fgulp-scale-images","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/derhuerst%2Fgulp-scale-images/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/derhuerst%2Fgulp-scale-images/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/derhuerst%2Fgulp-scale-images/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/derhuerst","download_url":"https://codeload.github.com/derhuerst/gulp-scale-images/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249016306,"owners_count":21198828,"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":["gulp","gulp-plugin","image","picture","resize","scale","sharp"],"created_at":"2024-10-03T00:06:38.021Z","updated_at":"2025-04-15T05:36:48.800Z","avatar_url":"https://github.com/derhuerst.png","language":"JavaScript","funding_links":["https://github.com/sponsors/derhuerst"],"categories":[],"sub_categories":[],"readme":"# gulp-scale-images\n\n**[Gulp](https://gulpjs.com) plugin to make each image smaller. Combined with [`flat-map`](https://npmjs.com/package/flat-map), you can create multiple variantes per image**, which is useful for [responsive images](https://developer.mozilla.org/en-US/docs/Learn/HTML/Multimedia_and_embedding/Responsive_images).\n\n[![npm version](https://img.shields.io/npm/v/gulp-scale-images.svg)](https://www.npmjs.com/package/gulp-scale-images)\n[![build status](https://api.travis-ci.org/derhuerst/gulp-scale-images.svg?branch=master)](https://travis-ci.org/derhuerst/gulp-scale-images)\n![ISC-licensed](https://img.shields.io/github/license/derhuerst/gulp-scale-images.svg)\n[![support me via GitHub Sponsors](https://img.shields.io/badge/support%20me-donate-fa7664.svg)](https://github.com/sponsors/derhuerst)\n[![chat with me on Twitter](https://img.shields.io/badge/chat%20with%20me-on%20Twitter-1da1f2.svg)](https://twitter.com/derhuerst)\n\n\n## Installing\n\n```shell\nnpm install gulp-scale-images --save-dev\n```\n\n\n## Usage\n\n`gulp-scale-images` expects the instructions for each file to be in `file.scale`. They may look like this:\n\n```js\n{\n\tmaxWidth: 300, // optional maximum width\n\tmaxHeight: 400, // optional maximum height\n\tformat: 'jpeg', // optional, one of ('jpeg', 'png', 'webp')\n\twithoutEnlargement: false, // optional, default is true\n\tfit: 'inside', // optional, default is 'cover', one of ('cover', 'contain', 'fill', 'inside', 'outside')\n\trotate: true, // optional\n\tmetadata: false, // copy metadata over?\n\tformatOptions: {} // optional, additional format options for sharp engine\n}\n```\n\n*Note*: You must specify at least one of `maxWidth` and `maxHeight`.\n\nYou can pass additional format options to Sharp engine using `formatOptions` parameter. Docs can be found at [Sharp API](http://sharp.pixelplumbing.com/en/stable/api-output/).\n\nAn example, we're going to generate *two* smaller variants for each input file. We're going to use [`flat-map`](https://npmjs.com/package/flat-map) for this:\n\n```js\nconst gulp = require('gulp')\nconst flatMap = require('flat-map').default\nconst scaleImages = require('gulp-scale-images')\n\nconst twoVariantsPerFile = (file, cb) =\u003e {\n\tconst pngFile = file.clone()\n\tpngFile.scale = {maxWidth: 500, maxHeight: 500, format: 'png'}\n\tconst jpegFile = file.clone()\n\tjpegFile.scale = {maxWidth: 700, format: 'jpeg'}\n\tcb(null, [pngFile, jpegFile])\n}\n\ngulp.src('src/*.{jpeg,jpg,png,gif}')\n.pipe(flatMap(twoVariantsPerFile))\n.pipe(scaleImages())\n.pipe(gulp.dest(…))\n```\n\n*Note:* Unlike `sharp`, `gulp-scale-image` is *not* designed to process untrusted user input. For example, it turns off `sharp`'s [input pixel limit](https://github.com/lovell/sharp/issues/1381#issuecomment-423182487) altogether.\n\n### Definining scale instructions based on metadata\n\nYou can let `gulp-scale-images` read the image metadata first, to device what to do with the file:\n\n```js\nconst readMetadata = require('gulp-scale-images/read-metadata')\nconst through = require('through2')\nconst scaleImages = require('gulp-scale-images')\n\nconst computeScaleInstructions = (file, _, cb) =\u003e {\n\treadMetadata(file, (err, meta) =\u003e {\n\t\tif (err) return cb(err)\n\t\tfile = file.clone()\n\t\tfile.scale = {\n\t\t\tmaxWidth: Math.floor(meta.width / 2),\n\t\t\tmaxHeight: Math.floor(meta.height / 2)\n\t\t}\n\t\tcb(null, file)\n\t})\n}\n\ngulp.src(…)\n.pipe(through.obj(computeScaleInstructions))\n.pipe(scaleImages())\n.pipe(gulp.dest(…))\n```\n\n### Custom output file names\n\nBy default, `gulp-scale-images` will use `{basename}.{maxWidth}w-{maxHeight}h.{format}` (e.g. `foo.500w-300h.jpeg`). You can define a custom logic though:\n\n```js\nconst path = require('path')\nconst scaleImages = require('gulp-scale-images')\n\nconst computeFileName = (output, scale, cb) =\u003e {\n\tconst fileName = [\n\t\tpath.basename(output.path, output.extname), // strip extension\n\t\tscale.maxWidth + 'w',\n\t\tscale.format || output.extname\n\t].join('.')\n\tcb(null, fileName)\n}\n\ngulp.src(…)\n.pipe(through.obj(computeScaleInstructions))\n.pipe(scaleImages(computeFileName)) // not that we pass computeFileName here\n.pipe(gulp.dest(…))\n```\n\n### `gulp-scale-images` works well with\n\n- [`flat-map`](https://www.npmjs.com/package/flat-map) – A flat map implementation for node streams. (One chunk in, `n` chunks out.)\n- [`replace-ext`](https://www.npmjs.com/package/replace-ext) – Replaces a file extension with another one.\n\n\n## Similar libraries\n\nSome similar libraries and why I think this one is better.\n\n- [`gulp-image-resize`](https://www.npmjs.com/package/gulp-image-resize)\n\t- uses [`gm`](https://npmjs.com/package/gm) instead of [`sharp`](https://npmjs.com/package/sharp), requires `gm` to be installed\n\t- supports only one scale instruction\n- [`gulp-sharp`](https://www.npmjs.com/package/gulp-sharp)\n\t- is not being maintained\n\t- has no tests\n\t- supports only one scale instruction\n- [`gulp-retinize`](https://www.npmjs.com/package/gulp-retinize)\n\t- doesn't seem to be maintained\n\t- uses [`gm`](https://npmjs.com/package/gm) instead of [`sharp`](https://npmjs.com/package/sharp), requires `gm` to be installed\n\t- only works for files on disk\n\t- supports only one scale instruction\n- [`gulp-imgconv`](https://www.npmjs.com/package/gulp-imgconv)\n\t- has no tests\n\t- supports only one scale instruction\n- [`gulp-inline-resize`](https://www.npmjs.com/package/gulp-inline-resize)\n\t- doesn't do *one thing*\n\t- uses [`gm`](https://npmjs.com/package/gm) instead of [`sharp`](https://npmjs.com/package/sharp), requires `gm` to be installed\n- [`gulp-unretina`](https://www.npmjs.com/package/gulp-unretina)\n\t- less flexible\n\t- uses [`gm`](https://npmjs.com/package/gm) instead of [`sharp`](https://npmjs.com/package/sharp), requires `gm` to be installed\n- [`gulp-gm-limit`](https://www.npmjs.com/package/gulp-gm-limit)\n\t- doesn't seem to be maintained\n\t- supports only one scale instruction\n- [`gulp-imgresize`](https://www.npmjs.com/package/gulp-imgresize)\n\t- no documentation\n\t- is not being maintained\n\t- has no tests\n\n\n## Contributing\n\nIf you have a question or have difficulties using `gulp-scale-images`, please double-check your code and setup first. If you think you have found a bug or want to propose a feature, refer to [the issues page](https://github.com/derhuerst/gulp-scale-images/issues).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fderhuerst%2Fgulp-scale-images","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fderhuerst%2Fgulp-scale-images","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fderhuerst%2Fgulp-scale-images/lists"}