载波图像大小调整不起作用

Carrierwave image resizing not working

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

uploader/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>

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

resize_to_limit 仅当图像尺寸大于指定尺寸时才会起作用。在此处阅读文档:link

你最好使用 resize_to_fil