forked from samuelgiles/papercrop
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
cb08c5b
commit d53d606
Showing
4 changed files
with
87 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
|
||
## Papercrop | ||
An easy extension for Paperclip to crop your image uploads using jCrop. | ||
|
||
### Installation | ||
Include papercrop in your Gemfile or install it by hand | ||
|
||
gem install papercrop | ||
|
||
You need to add the required files in your assets... | ||
|
||
In your application.js | ||
|
||
//= require jquery | ||
//= require jquery.jcrop | ||
//= require papercrop | ||
|
||
In your application.css | ||
|
||
*= require jquery.jcrop | ||
|
||
### Using Papercrop | ||
You are a few steps away to start cropping attachments. Let's start with the model, a user with avatar: | ||
|
||
has_attached_file :avatar, :styles => {:thumb => '50x50', :medium => '100x100'} | ||
crop_attached_file :avatar | ||
|
||
By default, the crop area and the preview box will have an aspect ratio of 1:1. | ||
You can modify that by passing a new aspect. | ||
|
||
crop_attached_file :snapshot, :aspect => "16:9" | ||
|
||
On the controller you can render a view after user creation, create a simple crop action, etc... whatever you like the most. Inside the form of a persisted user: | ||
|
||
<%= form_for @user do |f| %> | ||
<%= f.cropbox :avatar %> | ||
<%= f.crop_preview :avatar %> | ||
<%= f.submit 'Save' %> | ||
<% end %> | ||
|
||
Both helpers accept a :width option to customize their dimensions. The preview box has width 100 by default but the cropbox is unlimited in size (takes the original image width), so setting the cropbox width is interesting to avoid layout breaking with huge images. | ||
|
||
<%= form_for @user do |f| %> | ||
<%= f.cropbox :avatar, :width => 500 %> | ||
<%= f.crop_preview :avatar, :width => 150 %> | ||
<%= f.submit 'Save' %> | ||
<% end %> | ||
|
||
Regardless of the width passed, the preview box and the cropping area will have the aspect ratio defined in the model (1:1 by default) | ||
|
||
That's all! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,12 +7,12 @@ Gem::Specification.new do |s| | |
s.description = "Paperclip extension for cropping images" | ||
s.authors = ["Ruben Santamaria"] | ||
s.email = '[email protected]' | ||
s.homepage = 'http://rubygems.org/gems/papercrop' | ||
s.homepage = 'https://github.com/rsantamaria/papercrop' | ||
|
||
s.files = Dir.glob("{lib,vendor}/**/*") + %w(README.md) | ||
s.require_paths = ["lib"] | ||
|
||
s.add_dependency "rails", "~> 3.1" | ||
s.add_dependency "jquery-rails" | ||
s.add_dependency "paperclip", "~> 3.1.3" | ||
s.add_dependency "paperclip", "~> 3.1" | ||
end |