All Projects → janko → Image_processing

janko / Image_processing

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

Programming Languages

ruby
36898 projects - #4 most used programming language

Projects that are alternatives of or similar to Image processing

Node S3 Uploader
Flexible and efficient resize, rename, and upload images to Amazon S3 disk storage. Uses the official AWS Node SDK for transfer, and ImageMagick for image processing. Support for multiple image versions targets.
Stars: ✭ 237 (-60.5%)
Mutual labels:  image-processing, imagemagick, thumbnails
Php Legofy
Transform your images as if they were made out of LEGO bricks.
Stars: ✭ 161 (-73.17%)
Mutual labels:  image-processing, imagemagick
Nuxt Image Loader Module
An image loader module for nuxt.js that allows you to configure image style derivatives.
Stars: ✭ 135 (-77.5%)
Mutual labels:  image-processing, imagemagick
crops
🌄 Image thumbnail generation server
Stars: ✭ 37 (-93.83%)
Mutual labels:  imagemagick, thumbnails
Imager
Image processing proxy
Stars: ✭ 56 (-90.67%)
Mutual labels:  image-processing, imagemagick
Pgmagick
pgmagick is a yet another boost.python based wrapper for GraphicsMagick/ImageMagick.
Stars: ✭ 100 (-83.33%)
Mutual labels:  image-processing, imagemagick
imgout
On the fly thumbnail generator microservice using Elixir/OTP. (with Heroku Deploy Button)
Stars: ✭ 58 (-90.33%)
Mutual labels:  imagemagick, thumbnails
Lsix
Like "ls", but for images. Shows thumbnails in terminal using sixel graphics.
Stars: ✭ 2,635 (+339.17%)
Mutual labels:  imagemagick, thumbnails
Skeptick
Better ImageMagick for Ruby
Stars: ✭ 326 (-45.67%)
Mutual labels:  image-processing, imagemagick
Thumbnailator
Thumbnailator - a thumbnail generation library for Java
Stars: ✭ 3,845 (+540.83%)
Mutual labels:  image-processing, thumbnails
Magick
Magic, madness, heaven, sin
Stars: ✭ 362 (-39.67%)
Mutual labels:  image-processing, imagemagick
Java Thumbnailer
An extensible java library to create thumbnails of different file types (image, text)
Stars: ✭ 45 (-92.5%)
Mutual labels:  image-processing, thumbnails
Sv Images
Image manipulation library with an HTTP based API.
Stars: ✭ 7 (-98.83%)
Mutual labels:  image-processing, imagemagick
Spacechop
HTTP service for high-level image processing with first-class Docker support.
Stars: ✭ 133 (-77.83%)
Mutual labels:  image-processing, imagemagick
Flyimg
Dockerized PHP7 application runs as a Microservice to resize and crop images on the fly. Get optimised images with MozJPEG, WebP or PNG using ImageMagick. Includes face detection, cropping, face blurring, image rotation and many other options. Abstract storage based on FlySystem in order to store images on any provider (local, AWS S3...).
Stars: ✭ 762 (+27%)
Mutual labels:  image-processing, imagemagick
Wasm Imagemagick
Webassembly compilation of https://github.com/ImageMagick/ImageMagick & samples
Stars: ✭ 442 (-26.33%)
Mutual labels:  image-processing, imagemagick
Jekyll Gallery Generator
A Jekyll plugin that generates photo galleries from directories full of images.
Stars: ✭ 315 (-47.5%)
Mutual labels:  image-processing, imagemagick
Govips
A lightning fast image processing and resizing library for Go
Stars: ✭ 442 (-26.33%)
Mutual labels:  image-processing, imagemagick
Libvips
A fast image processing library with low memory needs.
Stars: ✭ 6,094 (+915.67%)
Mutual labels:  image-processing, imagemagick
Jquery Cropper
A jQuery plugin wrapper for Cropper.js.
Stars: ✭ 516 (-14%)
Mutual labels:  image-processing

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:
$ brew install imagemagick vips
  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.

$ brew install imagemagick vips

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

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].