0

I have an uploader, Avatar that I'd like to allow users to crop via custom coordinates their images from. I'm using a combination of Jcrop, Carrierwave and Cloudinary following the revised Railscast 182 episode.

On submit, the coordinates are stored but Carrierwave doesn't seem to recreate the versions with the new coordinates. Any ideas?

My Uploader

include Cloudinary::CarrierWave
  version :large do
    process :eager => true
    process :progressive => 'steep'
    cloudinary_transformation :secure => "true"
  end

  version :thumbnail do
    process :custom_crop
  end

  def extension_whitelist
     %w(jpg jpeg gif png)
  end

  def custom_crop
    return :x => model.crop_x, :y => model.crop_y, :width => model.crop_w, :height => model.crop_h, :crop => :crop
  end

My Model

class Profile < ActiveRecord::Base
  mount_uploader :avatar, AvatarUploader

  attr_accessor :crop_x, :crop_y, :crop_w, :crop_h
  after_update :crop_avatar

Crop Page

<h1>Crop Avatar</h1>


<%= image_tag @profile.avatar.url(:large), id: "cropbox" %>

<h4>Preview</h4>
<div style="width:100px; height:100px; overflow:hidden">
  <%= image_tag @profile.avatar.url(:large), :id => "preview" %>
</div>

<%= form_for ([:admin, @profile]) do |f| %>
  <% %w[x y w h].each do |attribute| %>
    <%= f.text_field "crop_#{attribute}" %>
  <% end %>
  <div class="actions">
    <%= f.submit "Crop" %>
  </div>
<% end %>

1 Answers1

0

Have you tried the following?:

version :thumbnail do
    cloudinary_transformation :x => model.crop_x, :y => model.crop_y, :width => model.crop_w, :height => model.crop_h, :crop => :crop
end
Itay Taragano
  • 1,901
  • 1
  • 11
  • 12