【问题标题】:Using Carrierwave, Cloudinary, Jcrop - Versions aren't recreated with custom crop coordinates使用 Carrierwave、Cloudinary、Jcrop - 不使用自定义裁剪坐标重新创建版本
【发布时间】:2018-01-10 06:09:45
【问题描述】:

我有一个上传器,Avatar,我想允许用户通过自定义坐标裁剪他们的图像。在修订后的 Railscast 182 集之后,我正在使用 Jcrop、Carrierwave 和 Cloudinary 的组合。

在提交时,坐标被存储,但 Carrierwave 似乎没有使用新坐标重新创建版本。有任何想法吗?

我的上传者

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

我的模特

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

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

裁剪页面

<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 %>

【问题讨论】:

    标签: ruby-on-rails ruby-on-rails-4 carrierwave jcrop cloudinary


    【解决方案1】:

    您是否尝试过以下方法?:

    version :thumbnail do
        cloudinary_transformation :x => model.crop_x, :y => model.crop_y, :width => model.crop_w, :height => model.crop_h, :crop => :crop
    end
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-03-13
      • 2013-10-29
      • 2023-03-31
      • 2013-02-01
      • 1970-01-01
      • 1970-01-01
      • 2015-08-07
      • 1970-01-01
      相关资源
      最近更新 更多