A summary of data about the Ruby ecosystem.

https://github.com/janko/image_processing

High-level image processing wrapper for libvips and ImageMagick/GraphicsMagick
https://github.com/janko/image_processing

Keywords

image-processing imagemagick minimagick ruby thumbnails vips

Keywords from Contributors

rubygems activerecord rack mvc activejob gem multithreading crash-reporting search-interface ruby-library

Last synced: about 14 hours ago
JSON representation

Repository metadata

High-level image processing wrapper for libvips and ImageMagick/GraphicsMagick

README.md

ImageProcessing

Provides higher-level image processing helpers that are commonly needed
when handling image uploads.

This gem can process images with either ImageMagick/GraphicsMagick or
libvips libraries. ImageMagick is a good default choice, especially if you
are migrating from another gem or library that uses ImageMagick. Libvips is a
newer library that can process images very rapidly
(often multiple times faster than ImageMagick).

Goal

The goal of this project is to have a single gem that contains all the
helper methods needed to resize and process images.

Currently, existing attachment gems (like Paperclip, CarrierWave, Refile,
Dragonfly, ActiveStorage, and others) implement their own custom image
helper methods. But why? That's not very DRY, is it?

Let's be honest. Image processing is a dark, mysterious art. So we want to
combine every great idea from all of these separate gems into a single awesome
library that is constantly updated with best-practice thinking about
how to resize and process images.

Installation

  1. Install ImageMagick and/or libvips:

In a Mac terminal:

  $ brew install imagemagick vips

In a debian/ubuntu terminal:

  $ sudo apt install imagemagick libvips
  1. Add the gem to your Gemfile:
gem "image_processing", "~> 1.0"

Usage

Processing is performed through ImageProcessing::Vips or
ImageProcessing::MiniMagick modules. Both modules share the same
chainable API for defining the processing pipeline:

require "image_processing/mini_magick"

processed = ImageProcessing::MiniMagick
  .source(file)
  .resize_to_limit(400, 400)
  .convert("png")
  .call

processed #=> #<Tempfile:/var/folders/.../image_processing20180316-18446-1j247h6.png>

This allows easy branching when generating multiple derivates:

require "image_processing/vips"

pipeline = ImageProcessing::Vips
  .source(file)
  .convert("png")

large  = pipeline.resize_to_limit!(800, 800)
medium = pipeline.resize_to_limit!(500, 500)
small  = pipeline.resize_to_limit!(300, 300)

The processing is executed on #call or when a processing method is called
with a bang (!).

processed = ImageProcessing::MiniMagick
  .convert("png")
  .resize_to_limit(400, 400)
  .call(image)

# OR

processed = ImageProcessing::MiniMagick
  .source(image) # declare source image
  .convert("png")
  .resize_to_limit(400, 400)
  .call

# OR

processed = ImageProcessing::MiniMagick
  .source(image)
  .convert("png")
  .resize_to_limit!(400, 400) # bang method

You can inspect the pipeline options at any point before executing it:

pipeline = ImageProcessing::MiniMagick
  .source(image)
  .loader(page: 1)
  .convert("png")
  .resize_to_limit(400, 400)
  .strip

pipeline.options
# => {:source=>#<File:/path/to/source.jpg>,
#     :loader=>{:page=>1},
#     :saver=>{},
#     :format=>"png",
#     :operations=>[[:resize_to_limit, [400, 400]], [:strip, []]],
#     :processor_class=>ImageProcessing::MiniMagick::Processor}

The source object needs to responds to #path, or be a String, a Pathname, or
a Vips::Image/MiniMagick::Tool object. Note that the processed file is
always saved to a new location, in-place processing is not supported.

ImageProcessing::Vips.source(File.open("source.jpg"))
ImageProcessing::Vips.source("source.jpg")
ImageProcessing::Vips.source(Pathname.new("source.jpg"))
ImageProcessing::Vips.source(Vips::Image.new_from_file("source.jpg"))

When #call is called without options, the result of processing is a
Tempfile object. You can save the processing result to a specific location by
passing :destination to #call, or pass save: false to retrieve the raw
Vips::Image/MiniMagick::Tool object.

pipeline = ImageProcessing::Vips.source(image)

pipeline.call #=> #<Tempfile ...>
pipeline.call(save: false) #=> #<Vips::Image ...>
pipeline.call(destination: "/path/to/destination")

You can continue reading the API documentation for specific modules:

See the wiki for additional "How To" guides for common scenarios. The wiki
is publicly editable, so you're encouraged to add your own guides.

Instrumentation

You can register an #instrumenter block for a given pipeline, which will wrap
the pipeline execution, allowing you to record performance metrics.

pipeline = ImageProcessing::Vips.instrumenter do |**options, &processing|
  options[:source]     #=> #<File:...>
  options[:loader]     #=> { fail: true }
  options[:saver]      #=> { quality: 85 }
  options[:format]     #=> "png"
  options[:operations] #=> [[:resize_to_limit, 500, 500], [:flip, [:horizontal]]]
  options[:processor]  #=> ImageProcessing::Vips::Processor

  ActiveSupport::Notifications.instrument("process.image_processing", **options) do
    processing.call # calls the pipeline
  end
end

pipeline
  .source(image)
  .loader(fail: true)
  .saver(quality: 85)
  .convert("png")
  .resize_to_limit(500, 500)
  .flip(:horizontal)
  .call # calls instrumenter

Contributing

Our test suite requires both imagemagick and libvips libraries to be installed.

In a Mac terminal:

$ brew install imagemagick vips

In a debian/ubuntu terminal:

sudo apt install imagemagick libvips

Afterwards you can run tests with

$ bundle exec rake test

Feedback

We welcome your feedback! What would you like to see added to image_processing?
How can we improve this gem? Open an issue and let us know!

Credits

The ImageProcessing::MiniMagick functionality was extracted from
refile-mini_magick. The chainable interface was heavily inspired by
HTTP.rb.

License

MIT


Owner metadata


GitHub Events

Total
Last Year

Committers metadata

Last synced: 2 days ago

Total Commits: 399
Total Committers: 24
Avg Commits per committer: 16.625
Development Distribution Score (DDS): 0.17

Commits in past year: 10
Committers in past year: 3
Avg Commits per committer in past year: 3.333
Development Distribution Score (DDS) in past year: 0.2

Name Email Commits
Janko Marohnić j****c@g****m 331
GustavoCaso g****o@g****m 33
Patrick Crowley p****k@m****m 11
Brendon Muir b****n@s****z 2
Geremia Taglialatela t****a 2
Petrik de Heus p****k@d****t 2
Bastian Bartmann b****n@g****m 1
Andrew Stevenson e****b 1
Chiorean Dan c****2@g****m 1
Florian Frank f****i@p****e 1
HM Tanbir t****5@g****m 1
Ken Collins k****n@m****t 1
Luke Rodgers l****s@g****m 1
Olle Jonsson o****n@g****m 1
Paul Filipow p****l@f****a 1
Paul Götze p****e@g****m 1
Paul Scarrone p****e@g****m 1
Ryuta Kamizono k****o@g****m 1
Thomas Menelle t****e@g****m 1
Vít Ondruch v****h@t****z 1
Yuji Yaginuma y****a@g****m 1
ahorek p****k@s****z 1
mark-young-atg 1****g 1
printercu p****u@g****m 1

Committer domains:


Issue and Pull Request metadata

Last synced: 4 months ago

Total issues: 94
Total pull requests: 35
Average time to close issues: 4 months
Average time to close pull requests: 4 months
Total issue authors: 71
Total pull request authors: 20
Average comments per issue: 5.03
Average comments per pull request: 3.83
Merged pull request: 32
Bot issues: 0
Bot pull requests: 0

Past year issues: 8
Past year pull requests: 4
Past year average time to close issues: about 19 hours
Past year average time to close pull requests: about 1 month
Past year issue authors: 8
Past year pull request authors: 2
Past year average comments per issue: 2.5
Past year average comments per pull request: 4.0
Past year merged pull request: 4
Past year bot issues: 0
Past year bot pull requests: 0

More stats: https://issues.ecosyste.ms/repositories/lookup?url=https://github.com/janko/image_processing

Top Issue Authors

  • mokolabs (7)
  • renchap (4)
  • metaskills (4)
  • janko (4)
  • etherbob (2)
  • gencer (2)
  • sandstrom (2)
  • ndbroadbent (2)
  • a-ta-ta (2)
  • wbotelhos (2)
  • doutatsu (2)
  • lws68825 (2)
  • PavarinE (1)
  • andyrue (1)
  • incubus (1)

Top Pull Request Authors

  • janko (5)
  • etherbob (4)
  • brendon (4)
  • tagliala (4)
  • mokolabs (3)
  • lukeasrodgers (2)
  • mark-young-atg (2)
  • p8 (2)
  • GustavoCaso (1)
  • coding-chimp (1)
  • ahorek (1)
  • y-yagi (1)
  • chioreandan (1)
  • olleolleolle (1)
  • metaskills (1)

Top Issue Labels

  • question (3)
  • enhancement (1)

Top Pull Request Labels


Package metadata

gem.coop: image_processing

High-level wrapper for processing images for the web with ImageMagick or libvips.

  • Homepage: https://github.com/janko/image_processing
  • Documentation: http://www.rubydoc.info/gems/image_processing/
  • Licenses: MIT
  • Latest release: 1.14.0 (published 10 months ago)
  • Last Synced: 2025-12-13T17:01:16.696Z (3 days ago)
  • Versions: 44
  • Dependent Packages: 0
  • Dependent Repositories: 0
  • Downloads: 91,964,549 Total
  • Docker Downloads: 2,004,226
  • Rankings:
    • Dependent repos count: 0.0%
    • Dependent packages count: 0.0%
    • Downloads: 0.288%
    • Average: 0.425%
    • Docker downloads count: 1.411%
  • Maintainers (3)
rubygems.org: image_processing

High-level wrapper for processing images for the web with ImageMagick or libvips.

proxy.golang.org: github.com/janko/image_processing

  • Homepage:
  • Documentation: https://pkg.go.dev/github.com/janko/image_processing#section-documentation
  • Licenses: mit
  • Latest release: v1.14.0 (published 10 months ago)
  • Last Synced: 2025-12-13T09:31:23.545Z (4 days ago)
  • Versions: 46
  • Dependent Packages: 0
  • Dependent Repositories: 0
  • Rankings:
    • Stargazers count: 2.196%
    • Forks count: 2.987%
    • Average: 6.39%
    • Dependent packages count: 9.576%
    • Dependent repos count: 10.802%

Dependencies

Gemfile rubygems
  • pry >= 0
image_processing.gemspec rubygems
  • dhash-vips >= 0 development
  • minispec-metadata >= 0 development
  • minitest ~> 5.8 development
  • minitest-hooks >= 1.4.2 development
  • rake >= 0 development
  • mini_magick >= 4.9.5, < 5
  • ruby-vips >= 2.0.17, < 3
.github/workflows/ci.yml actions
  • actions/checkout v2 composite
  • ruby/setup-ruby v1 composite

Score: 29.070546157004