RailsCarrierwaveFocuspoint

CarrierWave extension for specifying focus point on image before they upload on server and cropped.

This gem based on helper tool of jquery.focuspoint javascript library (https://github.com/jonom/jquery-focuspoint)

Installation

in Gemfile

    gem 'rails-carrierwave-focuspoint'

Usage

For using this gem you must add fields focus_x:decimal and focus_y:decimal to your db table used for storing CarrierWave picture information. Use migration:

    class AddFocusToUsers < ActiveRecord::Migration
      def change
        add_column :users, :focus_x, :decimal
        add_column :users, :focus_y, :decimal
      end
    end

in CarrierWave uploader

    class UserAvatarUploader < CarrierWave::Uploader::Base
      include CarrierWave::MiniMagick

      version :small do
        process crop_with_focuspoint: [100, 100]
      end

      version :big do
        process crop_with_focuspoint: [300, 200]
      end
    end

in model

    class User < ActiveRecord::Base
        mount_uploader :avatar, UserAvatarUploader
    end

in .js file

    //= require focuspoint.js
    //= require_self

    $(document).ready(function() {
        document.focuspoint.init(file_input_id: 'user_avatar');
    });

in .css file

    /*
    *= require focuspoint_control.css
    */

in view template

    = form_for @user do |f|
        = f.input :avatar
        = f.focuspoint_control :avatar

LICENSE

This project rocks and uses MIT-LICENSE.