{"id":17816454,"url":"https://github.com/zebrajaeger/gulp-scale-images","last_synced_at":"2025-04-02T08:26:03.500Z","repository":{"id":57170441,"uuid":"162887806","full_name":"zebrajaeger/gulp-scale-images","owner":"zebrajaeger","description":null,"archived":false,"fork":false,"pushed_at":"2018-12-23T14:50:18.000Z","size":31,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-10T19:16:25.147Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/zebrajaeger.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}},"created_at":"2018-12-23T12:13:18.000Z","updated_at":"2018-12-23T14:50:20.000Z","dependencies_parsed_at":"2022-08-27T12:02:00.160Z","dependency_job_id":null,"html_url":"https://github.com/zebrajaeger/gulp-scale-images","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zebrajaeger%2Fgulp-scale-images","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zebrajaeger%2Fgulp-scale-images/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zebrajaeger%2Fgulp-scale-images/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zebrajaeger%2Fgulp-scale-images/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zebrajaeger","download_url":"https://codeload.github.com/zebrajaeger/gulp-scale-images/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246779914,"owners_count":20832485,"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":[],"created_at":"2024-10-27T16:38:11.125Z","updated_at":"2025-04-02T08:26:03.474Z","avatar_url":"https://github.com/zebrajaeger.png","language":"JavaScript","funding_links":[],"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![ISC-licensed](https://img.shields.io/github/license/derhuerst/gulp-scale-images.svg)\n\n## Motivation\n\nThis is 'heavily inspired' by gulp-scale-images (https://www.npmjs.com/package/gulp-scale-images). And the lib does a great job.\n\nSo why fork this?\n\nOn my Orange and Raspberry Pi, the Sharp-Code node crashes because of memory errors and i did not found a workaround.\nSo i decided to take the plugin and separate the parts (Gulp plugin and resizer).\n\nNow there is a unique interface and you can decide to use sharp or jimp as resizing engine.  \n\n## Installing\n\n```shell\nnpm install @zebrajaeger/gulp-scale-images @zebrajaeger/gulp-scale-images-resize-sharp --save-dev\n```\n\nor \n\n```shell\nnpm install @zebrajaeger/gulp-scale-images @zebrajaeger/gulp-scale-images-resize-jimp --save-dev\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, respecting the aspect ratio\n\tmaxHeight: 400, // optional maximum height, respecting the aspect ratio\n\tformat: 'jpeg', // optional, one of ('jpeg', 'png', 'webp')\n\tquality: 80, // optional and only for jpeg target format\n\twithoutEnlargement: false // optional, default is true\n}\n```\n\n*Note*: You must specify at least one of `maxWidth` and `maxHeight`.\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('@zebrajaeger/gulp-scale-images')\n\n// choose one of them\nconst scaleImagesResize = require('@zebrajaeger/gulp-scale-images-resize-sharp')\nconst scaleImagesResize = require('@zebrajaeger/gulp-scale-images-resize-jimp')\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(scaleImagesResize))\n.pipe(gulp.dest(…))\n```\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('@zebrajaeger/gulp-scale-images')\n\n// choose one of them\nconst scaleImagesResize = require('@zebrajaeger/gulp-scale-images-resize-sharp')\nconst scaleImagesResize = require('@zebrajaeger/gulp-scale-images-resize-jimp')\n\nconst computeScaleInstructions = (file, _, cb) =\u003e {\n\treadMetadata(file.path, (err, meta) =\u003e {\n\t\tif (err) return cb(err)\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(scaleImagesResize))\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('@zebrajaeger/gulp-scale-images')\n\n// choose one of them\nconst scaleImagesResize = require('@zebrajaeger/gulp-scale-images-resize-sharp')\nconst scaleImagesResize = require('@zebrajaeger/gulp-scale-images-resize-jimp')\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(scaleImagesResize, 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## 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/zebrajaeger/gulp-scale-images/issues).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzebrajaeger%2Fgulp-scale-images","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzebrajaeger%2Fgulp-scale-images","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzebrajaeger%2Fgulp-scale-images/lists"}