{"id":13527243,"url":"https://github.com/nodeca/image-blob-reduce","last_synced_at":"2025-05-16T12:02:30.092Z","repository":{"id":40464000,"uuid":"274896122","full_name":"nodeca/image-blob-reduce","owner":"nodeca","description":"Resize image blobs with high quality. Pica's wrapper to work with file inputs.","archived":false,"fork":false,"pushed_at":"2024-05-13T12:19:32.000Z","size":267,"stargazers_count":289,"open_issues_count":3,"forks_count":33,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-04-13T00:42:14.731Z","etag":null,"topics":["image","resize"],"latest_commit_sha":null,"homepage":"https://nodeca.github.io/image-blob-reduce/","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/nodeca.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null},"funding":{"open_collective":"puzrin","patreon":"puzrin"}},"created_at":"2020-06-25T11:12:29.000Z","updated_at":"2025-03-27T13:02:58.000Z","dependencies_parsed_at":"2022-07-14T03:20:41.988Z","dependency_job_id":null,"html_url":"https://github.com/nodeca/image-blob-reduce","commit_stats":{"total_commits":79,"total_committers":5,"mean_commits":15.8,"dds":0.07594936708860756,"last_synced_commit":"0e974bb9dac8e47121bdb4bbb736b5b965c79b70"},"previous_names":[],"tags_count":19,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nodeca%2Fimage-blob-reduce","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nodeca%2Fimage-blob-reduce/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nodeca%2Fimage-blob-reduce/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nodeca%2Fimage-blob-reduce/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nodeca","download_url":"https://codeload.github.com/nodeca/image-blob-reduce/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248650417,"owners_count":21139672,"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":["image","resize"],"created_at":"2024-08-01T06:01:43.944Z","updated_at":"2025-04-13T00:42:22.010Z","avatar_url":"https://github.com/nodeca.png","language":"JavaScript","funding_links":["https://opencollective.com/puzrin","https://patreon.com/puzrin"],"categories":["JavaScript"],"sub_categories":[],"readme":"image-blob-reduce - downscale blobs with images inside\n======================================================\n\n[![CI](https://github.com/nodeca/image-blob-reduce/workflows/CI/badge.svg?branch=master)](https://github.com/nodeca/image-blob-reduce/actions)\n[![NPM version](https://img.shields.io/npm/v/image-blob-reduce.svg)](https://www.npmjs.org/package/image-blob-reduce)\n\n\n\u003e Wrapper for [pica](https://github.com/nodeca/pica) to work with blobs, with\n\u003e some sugar.\n\nThis is `pica` wrapper for convenient work with images from file input fields.\nWhile `pica` works with raw bitmaps, this package operates with \"image files\".\nAdditional features are:\n\n- \\[jpeg] Apply orientation to downscaled result.\n- \\[jpeg] Keep metadata, but with patched orientation \u0026 removed original color\n  profile.\n- Easy to monkey-patch for your needs.\n\n**[Demo](https://nodeca.github.io/image-blob-reduce/)**\n\n\nInstall\n-------\n\n```sh\nnpm install image-blob-reduce\n```\n\n\nKnown issues\n------------\n\nThis package is not compaible with some minification options. If you use\n`terser`, disable `evaluate` or all `compress` options:\n\n- `{ compress: { evaluate: false } }`\n- `{ compress: false }`\n\nThis should not cause notable assets increase\n\n\nUsage\n-----\n\n```js\nconst reduce = require('image-blob-reduce')();\n\n//...\n\nreduce\n  .toBlob(image_blob, { max: 1000 })\n  .then(blob =\u003e { ... });\n```\n\nIf you load prebuild script in browser, use `window.ImageBlobReduce`\n\n\nAPI\n---\n\n### new ImageBlobReduce([options])\n\nCreate new reducer. Options:\n\n- `pica` - instance of `pica`, if you wish different defaults or shareable\n  webworkers pool.\n\nShort call: `require('image_blob_reduce')()`\n\n\n### .toBlob(in_blob, options) =\u003e Promise(out_blob)\n\nDownscale image to fit into `max`\\*`max` size. If blob contains jpeg, then\norientation is applied and metadata from original image reused (with minimal\nchange).\n\nOptions:\n\n- __max__ - max allowed image size.\n- __pica `.resize()` options__ - `alpha`, `unsharpAmount`, `unsharpRadius`,\n  `unsharpThreshold`, `cancelToken`\n\n\n### .toCanvas(in_blob, options) =\u003e Promise(out_canvas)\n\nThe same as `.toBlob()`, but with canvas output.\n\n\n### .before(method_name, hook_fn)\n\nInject your custom handler before specified method. See `.init()` source code\nfor example.\n\n\n### .after(method_name, hook_fn)\n\nThe same as `.before()`, but handler is injected after specified method.\n\n\n### .use(plugin_init, ...params) =\u003e this\n\nSugar to simplify assign of external plugins. Just calls\n`plugin_init(this, ...params)`.\n\n\n### .utils\n\n`require('./lib/utils')`, to simplify modifications.\n\n\n### Reexports\n\n- `ImageBlobReduce.pica` =\u003e `require('pica')` - useful to customize pica options.\n\n\n## Customization\n\nSince it's difficult to implement all possible options, this package is\nspecially designed for easy customization. See source code first.\n\n- You can inherit class \u0026 replace existing methods.\n- You can add extra actions before/after existing method.\n- You can override existing methods of instance.\n\nFor example, if you wish force output to be always jpeg with some quality:\n\n```js\nconst reducer = require('image-blob-reduce')();\n\nreducer._create_blob = function (env) {\n  return this.pica.toBlob(env.out_canvas, 'image/jpeg', 0.8)\n    .then(function (blob) {\n      env.out_blob = blob;\n      return env;\n    });\n};\n```\n\nOr rewrite scaling logic, introducing `min` option instead:\n\n```js\nconst reducer = require('image-blob-reduce')();\n\nreducer._calculate_size = function (env) {\n  const scale_factor = env.opts.min / Math.min(env.image.width, env.image.height);\n\n  if (scale_factor \u003e 1) scale_factor = 1;\n\n  env.transform_width = Math.max(Math.round(env.image.width * scale_factor), 1);\n  env.transform_height = Math.max(Math.round(env.image.height * scale_factor), 1);\n  \n  return env;\n};\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnodeca%2Fimage-blob-reduce","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnodeca%2Fimage-blob-reduce","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnodeca%2Fimage-blob-reduce/lists"}