Presto
Presto allows you to quickly manipulate images in Ruby with minimal effort. It is currently a wrapper for the MiniMagick DSL.
Tested on the following Rubies: MRI 2.0.0.
Installation
Add the gem to your Gemfile:
gem 'presto'
Since Presto is a wrapper for the MiniMagick gem, it will also need to be included in your gemfile.
Usage
Require the Presto mini_magick extension after mini_magick:
require 'mini_magick'
require 'presto/mini_magick'
Open and manipulate images using MiniMagick and the new presto method
image = MiniMagick::Image.open("input.jpg")
image.presto(w:500, h:200, fit:'crop', q:75, fm:'jpg', bg:'e2e2e2')
image.write "output.jpg"
Api
w, h
The width and height in pixels of the output image.
If only one dimension is specified, the other dimension will be calculated according to the aspect ratio of the input image.
fit
Controls how the image is transformed to reach the target dimensions. Possible values are:
- clip (default): Resize the image to fit within the target dimensions while maintaining the aspect ratio.
- crop: Resize the image to fill the target dimensions, and crop, removing any portion of the image laying outside of the target dimensions.
- fill: Resize the image to fit within the target dimensions, and fill the remaining whitespace with the assigned background color.
- scale: Scale the image to the target dimensions, and disregard the image's aspect ratio.
- max: Resize the image to fit within the target dimensions, if it is larger. This option will not resize an image if it is already equal to or less than the target dimensions.
bg (background)
Assigns the background color to use when excess space or transparency is encountered. The hexidecimal color can be assigned in any of the following formats:
- 3-Value RGB: F00 (red)
- 6-Value RRGGBB: 00FF00 (green)
- 8-Value RRGGBBAA: FFFFFF00 (transparent white)
fm (format)
Sets the format of the output image. Valid values are jpg or png.
q (quality)
A numeric value between 1 (worst) and 100 (best) representing the quality of the output image. Only applies to jpg format images.
Contributing
- Fork it
- Create your feature branch (
git checkout -b my-new-feature) - Commit your changes (
git commit -am 'Add some feature') - Push to the branch (
git push origin my-new-feature) - Create new Pull Request