Dragonfly libvips
Dragonfly analysers and processors for libvips image processing library
From the libvips README:
libvips is a 2D image processing library. Compared to similar libraries, libvips runs quickly and uses little memory. libvips is licensed under the LGPL 2.1+.
Installation
Add this line to your application's Gemfile:
gem 'dragonfly_libvips'
And then execute:
$ bundle
Or install it yourself as:
$ gem install dragonfly_libvips
Dependencies
The vips library and its dependencies.
Usage
Configure your app the usual way:
Dragonfly.app.configure do
plugin :libvips
end
Processors
Thumb
Create a thumbnail by resizing/cropping
image.thumb('40x30')
Below are some examples of geometry strings for thumb
:
'400x300' # resize, maintain aspect ratio
'400x' # resize width, maintain aspect ratio
'x300' # resize height, maintain aspect ratio
'400x300<' # resize only if the image is smaller than this
'400x300>' # resize only if the image is larger than this
Encode
Change the encoding with
image.encode('jpg')
optionally pass output arguments (specific to format)
image.encode('jpg', 'Q=50')
Rotate
Rotate a number of degrees with
image.rotate(90)
Vips
Perform an arbitrary vips
command
image.vips('resize', '0.5', { 'input_args' => 'page=2', 'output_args' => 'Q=50', 'format' => 'jpg' })
corresponds to the command-line
vips resize <original_path>[page=2] <new_path>[Q=50] 0.5
Vipsthumbnail
Perform an arbitrary vipsthumbnail
command
image.vipsthumbnail('--size=100x100', { 'input_args' => 'page=2', 'output_args' => 'Q=50', 'format' => 'jpg' })
corresponds to the command-line
vipsthumbnail <original_path>[page=2] --size=100x100 -o <new-path>[Q=50]
Analysers
The following methods are provided
image.width # => 280
image.height # => 355
image.aspect_ratio # => 0.788732394366197
image.portrait? # => true
image.landscape? # => false
image.format # => 'png'
image.image? # => true
Configuration
Dragonfly.app.configure do
plugin :libvips,
vips_command: "/opt/local/bin/vips" # defaults to "vips"
vipsheader_command: "/opt/local/bin/vipsheader" # defaults to "vipsheader"
vipsthumbnail_command: "/opt/local/bin/vipsthumbnail" # defaults to "vipsthumbnail"
end
Acknowledgements
This plugin, its structure, sample files, tests as well as this README are based on the original Dragonfly's ImageMagick plugin by Mark Evans.
Development
After checking out the repo, run bin/setup
to install dependencies. Then, run rake test
to run the tests. You can also run bin/console
for an interactive prompt that will allow you to experiment.
To install this gem onto your local machine, run bundle exec rake install
. To release a new version, update the version number in version.rb
, and then run bundle exec rake release
, which will create a git tag for the version, push git commits and tags, and push the .gem
file to rubygems.org.
Contributing
Bug reports and pull requests are welcome on GitHub at https://github.com/tomasc/dragonfly_libvips.
License
The gem is available as open source under the terms of the MIT License.