Carrierwave图像调整大小不起作用

时间:2015-02-23 12:53:10

标签: jquery ruby-on-rails ruby imagemagick carrierwave

我无法将我放入rails应用程序中的图像缩放器正常工作。我在picture_uploader.rb添加了一个缩放器,但它无法正常工作:

上载/ picture_uploader.rb

class PictureUploader < CarrierWave::Uploader::Base
  include CarrierWave::MiniMagick
  process resize_to_limit: [400, 400]

  if Rails.env.production?
    storage :fog
  else
    storage :file
  end

  # Override the directory where uploaded files will be stored.
  # This is a sensible default for uploaders that are meant to be mounted:
  def store_dir
    "uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
  end

  # Add a white list of extensions which are allowed to be uploaded.
  def extension_white_list
    %w(jpg jpeg gif png)
  end
end

这是上传者:

home.html.erb

  <span class="picture">
    <%= f.file_field :picture, accept: 'image/jpeg,image/gif,image/png' %>
  </span>

我需要以相同的尺寸上传图片。

1 个答案:

答案 0 :(得分:0)

resize_to_limit只有在图像大小大于指定值时才会生效。阅读文档:link

最好使用resize_to_fil