Skip to content

Commit

Permalink
Formatted README.md.
Browse files Browse the repository at this point in the history
  • Loading branch information
kirtithorat committed Jul 30, 2014
1 parent fa2aab2 commit 22e183b
Showing 1 changed file with 48 additions and 48 deletions.
96 changes: 48 additions & 48 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,37 +39,37 @@ Generate a coffeescript for cropping:

this should give you a file in:

app/assets/javascripts/users.js.coffee
app/assets/javascripts/users.js.coffee

## Usage

Open your model file and add the cropper:

class User < ActiveRecord::Base
mount_uploader :avatar, AvatarUploader
crop_uploaded :avatar ## Add this
end
class User < ActiveRecord::Base
mount_uploader :avatar, AvatarUploader
crop_uploaded :avatar ## Add this
end

Render a view after creating/updating a user, add a `crop` action in your `controller.` For example:

def create
@user = User.new(user_params)
respond_to do |format|
if @user.save
format.html {
if params[:user][:avatar].present?
render :crop ## Render the view for cropping
else
redirect_to @user, notice: 'User was successfully created.'
end
}
format.json { render action: 'show', status: :created, location: @user }
else
format.html { render action: 'new' }
format.json { render json: @user.errors, status: :unprocessable_entity }
end
def create
@user = User.new(user_params)
respond_to do |format|
if @user.save
format.html {
if params[:user][:avatar].present?
render :crop ## Render the view for cropping
else
redirect_to @user, notice: 'User was successfully created.'
end
}
format.json { render action: 'show', status: :created, location: @user }
else
format.html { render action: 'new' }
format.json { render json: @user.errors, status: :unprocessable_entity }
end
end
end

For `Rails 4.x`, whitelist the cropping attributes - `fieldname_crop_x`, `fieldname_crop_y`, `fieldname_crop_w`, `fieldname_crop_h`.

Expand All @@ -92,7 +92,7 @@ In the carrierwave uploader, say `AvatarUploader`:

Call process on the version you would like to be cropped:

## If ONLY "thumb" version is to be cropped
## If ONLY "thumb" version is to be cropped
version :jumbo do
resize_to_limit(600,600)
end
Expand All @@ -113,60 +113,60 @@ If there are no versions, and original file is to be cropped directly then call

**To use `rmagick`, add it in your `Gemfile` as:**

gem 'rmagick', :require => 'RMagick' ## Specify appropriate version, if needed
gem 'rmagick', :require => 'RMagick' ## Specify appropriate version, if needed

Run `bundle`

Include it in your CarrierWave Uploader. For example:

class AvatarUploader < CarrierWave::Uploader::Base
include CarrierWave::RMagick
...
end
class AvatarUploader < CarrierWave::Uploader::Base
include CarrierWave::RMagick
## ...
end

**To use `mini_magick`, add it in your `Gemfile` as:**

gem 'mini_magick' ## Specify appropriate version, if needed
gem 'mini_magick' ## Specify appropriate version, if needed

Run `bundle`

Include it in your CarrierWave Uploader. For example:

class AvatarUploader < CarrierWave::Uploader::Base
include CarrierWave::MiniMagick
...
end
class AvatarUploader < CarrierWave::Uploader::Base
include CarrierWave::MiniMagick
## ...
end

3. Supports cropping of ONE attachment per model. Can be directly applied on original attachment if no versions exists.

process crop: :avatar
process crop: :avatar

4. Supports cropping of MULTIPLE versions of one attachment per model.
5. In form helpers, by default *original image* is rendered. To render a specific version for cropping pass `version` option. For example:

<%= f.cropbox :avatar , version: :medium %>
<%= f.previewbox :avatar , version: :medium %> ## Pass the same version as specified in cropbox
<%= f.cropbox :avatar , version: :medium %>
<%= f.previewbox :avatar , version: :medium %> ## Pass the same version as specified in cropbox

6. By default `previewbox` has `100x100` dimensions and `cropbox` defaults to the target geometry for the version.
`width` and `height` can be specified for these form helpers. BUT If you override ONE of width/height you MUST override both, otherwise passed option would be ignored.

<%= f.cropbox :avatar, width: 550, height: 600 %>
<%= f.previewbox :avatar, width: 200, height: 200 %>
<%= f.cropbox :avatar, width: 550, height: 600 %>
<%= f.previewbox :avatar, width: 200, height: 200 %>

7. By default, `process crop: :avatar` will create the cropped version based on original image.
To resize the image to a particular dimension before cropping, pass two more arguments `width` and `height`.

## If ONLY "thumb" version is to be cropped
version :jumbo do
resize_to_limit(600,600)
end

version :thumb do
## To crop this version based on `jumbo` version, pass width = 600 and height = 600
## Specify both width and height values otherwise they would be ignored
process crop: [:avatar, 600, 600]
resize_to_limit(100,100)
end
## If ONLY "thumb" version is to be cropped
version :jumbo do
resize_to_limit(600,600)
end

version :thumb do
## To crop this version based on `jumbo` version, pass width = 600 and height = 600
## Specify both width and height values otherwise they would be ignored
process crop: [:avatar, 600, 600]
resize_to_limit(100,100)
end

### Credits and resources
* [CarrierWave](https://github.com/carrierwaveuploader/carrierwave)
Expand Down

0 comments on commit 22e183b

Please sign in to comment.