How to resize and image watermarks in Ruby / Rails?
I would recommend using Paperclip to load images.
With Paperclip, you define how you want the images to be processed after loading.
Automatic resizing is done by setting values ββin your load model
class User < ActiveRecord::Base
has_attached_file :avatar, :styles => { :medium => "300x300>", :thumb => "100x100>" }
end
Here is a good example of creating Post Processors and another one to add using ImageMagick .
It should be noted that you already have the app (with the images loaded) live, you can run the Paperclip commands over it again with the command:
rake paperclip:refresh ModelName RAILS_ENV=production
source to share
I am currently using RMagick for several products and it works great for me. However, people are constantly complaining about memory usage . However, the documentation can be a little confusing.
A new project I've heard about is MagickWand for Ruby . But I have no experience with that.
source to share
I just recommend a gem that I wrote myself:
Github page: https://github.com/wrymax/image_clipper
It's a very simple use of this for resizing and watermarking. Also it works well with Paperclip in ROR.
Just add:
gem install image_clipper
And install ImageMagick as base image library:
brew install imagemagick
Sample code:
image.resize('200x100', save_new_file_path)
image.resize('35%')
image.watermarking(watermark_image_path)
Hope it helps.
source to share