{"id":13586820,"url":"https://github.com/janko/image_processing","last_synced_at":"2025-05-13T17:10:12.600Z","repository":{"id":41261371,"uuid":"43610049","full_name":"janko/image_processing","owner":"janko","description":"High-level image processing wrapper for libvips and ImageMagick/GraphicsMagick","archived":false,"fork":false,"pushed_at":"2025-02-10T21:47:20.000Z","size":12592,"stargazers_count":898,"open_issues_count":9,"forks_count":83,"subscribers_count":21,"default_branch":"master","last_synced_at":"2025-05-01T08:09:55.561Z","etag":null,"topics":["image-processing","imagemagick","minimagick","ruby","thumbnails","vips"],"latest_commit_sha":null,"homepage":"","language":"Ruby","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/janko.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":"CODE_OF_CONDUCT.md","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":"2015-10-03T18:36:53.000Z","updated_at":"2025-04-26T15:36:32.000Z","dependencies_parsed_at":"2023-01-30T22:46:48.716Z","dependency_job_id":"5e68fff0-8d4e-4e1a-a956-43a59c007c04","html_url":"https://github.com/janko/image_processing","commit_stats":{"total_commits":389,"total_committers":24,"mean_commits":"16.208333333333332","dds":"0.17223650385604117","last_synced_commit":"264b0b1d01689f49622562605692b9d353eee4d1"},"previous_names":[],"tags_count":46,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/janko%2Fimage_processing","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/janko%2Fimage_processing/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/janko%2Fimage_processing/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/janko%2Fimage_processing/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/janko","download_url":"https://codeload.github.com/janko/image_processing/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252662315,"owners_count":21784767,"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-processing","imagemagick","minimagick","ruby","thumbnails","vips"],"created_at":"2024-08-01T15:05:50.048Z","updated_at":"2025-05-13T17:10:12.551Z","avatar_url":"https://github.com/janko.png","language":"Ruby","funding_links":[],"categories":["Ruby","Image Processing","Uncategorized","Images"],"sub_categories":["Uncategorized"],"readme":"# ImageProcessing\n\nProvides higher-level image processing helpers that are commonly needed\nwhen handling image uploads.\n\nThis gem can process images with either [ImageMagick]/[GraphicsMagick] or\n[libvips] libraries. ImageMagick is a good default choice, especially if you\nare migrating from another gem or library that uses ImageMagick. Libvips is a\nnewer library that can process images [very rapidly][libvips performance]\n(often multiple times faster than ImageMagick).\n\n\n## Goal\n\nThe goal of this project is to have a single gem that contains all the\nhelper methods needed to resize and process images.\n\nCurrently, existing attachment gems (like Paperclip, CarrierWave, Refile,\nDragonfly, ActiveStorage, and others) implement their own custom image\nhelper methods. But why? That's not very DRY, is it?\n\nLet's be honest. Image processing is a dark, mysterious art. So we want to\ncombine every great idea from all of these separate gems into a single awesome\nlibrary that is constantly updated with best-practice thinking about\nhow to resize and process images.\n\n\n## Installation\n\n1. Install ImageMagick and/or libvips:\n\nIn a Mac terminal:\n\n```sh\n  $ brew install imagemagick vips\n  ```\n\n In a debian/ubuntu terminal:\n\n```sh\n  $ sudo apt install imagemagick libvips\n  ```\n\n2. Add the gem to your Gemfile:\n\n  ```rb\n  gem \"image_processing\", \"~\u003e 1.0\"\n  ```\n\n\n## Usage\n\nProcessing is performed through **[`ImageProcessing::Vips`]** or\n**[`ImageProcessing::MiniMagick`]** modules. Both modules share the same\nchainable API for defining the processing pipeline:\n\n```rb\nrequire \"image_processing/mini_magick\"\n\nprocessed = ImageProcessing::MiniMagick\n  .source(file)\n  .resize_to_limit(400, 400)\n  .convert(\"png\")\n  .call\n\nprocessed #=\u003e #\u003cTempfile:/var/folders/.../image_processing20180316-18446-1j247h6.png\u003e\n```\n\nThis allows easy branching when generating multiple derivates:\n\n```rb\nrequire \"image_processing/vips\"\n\npipeline = ImageProcessing::Vips\n  .source(file)\n  .convert(\"png\")\n\nlarge  = pipeline.resize_to_limit!(800, 800)\nmedium = pipeline.resize_to_limit!(500, 500)\nsmall  = pipeline.resize_to_limit!(300, 300)\n```\n\nThe processing is executed on `#call` or when a processing method is called\nwith a bang (`!`).\n\n```rb\nprocessed = ImageProcessing::MiniMagick\n  .convert(\"png\")\n  .resize_to_limit(400, 400)\n  .call(image)\n\n# OR\n\nprocessed = ImageProcessing::MiniMagick\n  .source(image) # declare source image\n  .convert(\"png\")\n  .resize_to_limit(400, 400)\n  .call\n\n# OR\n\nprocessed = ImageProcessing::MiniMagick\n  .source(image)\n  .convert(\"png\")\n  .resize_to_limit!(400, 400) # bang method\n```\n\nYou can inspect the pipeline options at any point before executing it:\n\n```rb\npipeline = ImageProcessing::MiniMagick\n  .source(image)\n  .loader(page: 1)\n  .convert(\"png\")\n  .resize_to_limit(400, 400)\n  .strip\n\npipeline.options\n# =\u003e {:source=\u003e#\u003cFile:/path/to/source.jpg\u003e,\n#     :loader=\u003e{:page=\u003e1},\n#     :saver=\u003e{},\n#     :format=\u003e\"png\",\n#     :operations=\u003e[[:resize_to_limit, [400, 400]], [:strip, []]],\n#     :processor_class=\u003eImageProcessing::MiniMagick::Processor}\n```\n\nThe source object needs to responds to `#path`, or be a String, a Pathname, or\na `Vips::Image`/`MiniMagick::Tool` object. Note that the processed file is\nalways saved to a new location, in-place processing is not supported.\n\n```rb\nImageProcessing::Vips.source(File.open(\"source.jpg\"))\nImageProcessing::Vips.source(\"source.jpg\")\nImageProcessing::Vips.source(Pathname.new(\"source.jpg\"))\nImageProcessing::Vips.source(Vips::Image.new_from_file(\"source.jpg\"))\n```\n\nWhen `#call` is called without options, the result of processing is a\n`Tempfile` object. You can save the processing result to a specific location by\npassing `:destination` to `#call`, or pass `save: false` to retrieve the raw\n`Vips::Image`/`MiniMagick::Tool` object.\n\n```rb\npipeline = ImageProcessing::Vips.source(image)\n\npipeline.call #=\u003e #\u003cTempfile ...\u003e\npipeline.call(save: false) #=\u003e #\u003cVips::Image ...\u003e\npipeline.call(destination: \"/path/to/destination\")\n```\n\nYou can continue reading the API documentation for specific modules:\n\n* **[`ImageProcessing::Vips`]**\n* **[`ImageProcessing::MiniMagick`]**\n\nSee the **[wiki]** for additional \"How To\" guides for common scenarios. The wiki\nis publicly editable, so you're encouraged to add your own guides.\n\n## Instrumentation\n\nYou can register an `#instrumenter` block for a given pipeline, which will wrap\nthe pipeline execution, allowing you to record performance metrics.\n\n```rb\npipeline = ImageProcessing::Vips.instrumenter do |**options, \u0026processing|\n  options[:source]     #=\u003e #\u003cFile:...\u003e\n  options[:loader]     #=\u003e { fail: true }\n  options[:saver]      #=\u003e { quality: 85 }\n  options[:format]     #=\u003e \"png\"\n  options[:operations] #=\u003e [[:resize_to_limit, 500, 500], [:flip, [:horizontal]]]\n  options[:processor]  #=\u003e ImageProcessing::Vips::Processor\n\n  ActiveSupport::Notifications.instrument(\"process.image_processing\", **options) do\n    processing.call # calls the pipeline\n  end\nend\n\npipeline\n  .source(image)\n  .loader(fail: true)\n  .saver(quality: 85)\n  .convert(\"png\")\n  .resize_to_limit(500, 500)\n  .flip(:horizontal)\n  .call # calls instrumenter\n```\n\n## Contributing\n\nOur test suite requires both `imagemagick` and `libvips` libraries to be installed.\n\nIn a Mac terminal:\n\n```\n$ brew install imagemagick vips\n```\n\nIn a debian/ubuntu terminal:\n```shell\nsudo apt install imagemagick libvips\n```\n\nAfterwards you can run tests with\n\n```\n$ bundle exec rake test\n```\n\n\n## Feedback\n\nWe welcome your feedback! What would you like to see added to image_processing?\nHow can we improve this gem? Open an issue and let us know!\n\n\n## Credits\n\nThe `ImageProcessing::MiniMagick` functionality was extracted from\n[refile-mini_magick]. The chainable interface was heavily inspired by\n[HTTP.rb].\n\n\n## License\n\n[MIT](LICENSE.txt)\n\n[libvips]: http://libvips.github.io/libvips/\n[ImageMagick]: https://www.imagemagick.org\n[GraphicsMagick]: http://www.graphicsmagick.org\n[`ImageProcessing::Vips`]: doc/vips.md#readme\n[`ImageProcessing::MiniMagick`]: doc/minimagick.md#readme\n[refile-mini_magick]: https://github.com/refile/refile-mini_magick\n[wiki]: https://github.com/janko/image_processing/wiki\n[HTTP.rb]: https://github.com/httprb/http\n[libvips performance]: https://github.com/libvips/libvips/wiki/Speed-and-memory-use\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjanko%2Fimage_processing","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjanko%2Fimage_processing","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjanko%2Fimage_processing/lists"}