No commit activity in last 3 years
No release in over 3 years
RailsCarrierwaveFocuspoint is a wrapper for jquery-focuspoint library.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Runtime

~> 3.2.21
 Project Readme

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.