Using jCrop with cloudinary through rails 4 to crop before creating image

99封情书 提交于 2019-12-05 19:21:01

You can have a look at the following link for the information about Custom coordinates based cropping with Carrierwave: http://cloudinary.com/documentation/rails_carrierwave#custom_coordinates_based_cropping

Ok I solved it by doing the following... took the @ off of the update callbacks and that made the fields get updated with the cropping parameters (bad syntax on my part). Then I persistantly stored the cropping values in the model and got rid of the image.revisions! callback and then put the following code in my uploader:

class ImageUploader < CarrierWave::Uploader::Base
  #include Sprockets::Helpers::RailsHelper
  #include Sprockets::Helpers::IsolatedHelper

  include Cloudinary::CarrierWave

  process :tags => ["profile pic"]
  process :convert => "jpg"

  version :thumbnail do
    cloudinary_transformation :transformation => [
        {:width => 400, :height => 400, :crop => :limit}]
    process :custom_crop 
  end  

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

followed by this in my view:

<%= image_tag(@dog.photos.last.image.thumbnail.url, :width => 150, :height => 150, :crop => :fill, class: "img-circle center") %>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!