2015-02-23 36 views
0

我無法獲取圖像大小調整,我放在我的Rails應用程序正常工作。我添加了一個大小調整到picture_uploader.rb但它不能正常工作:Carrierwave圖像調整大小不起作用

上傳/ 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

會更好你上傳圖片比400×400小? – sonalkr132 2015-02-23 13:28:14

+0

這是問題所在。我使用的是來自谷歌圖片的屏幕截圖,低於400x400。從我的iPhone使用過的照片,它工作! – 2015-02-25 21:06:25

回答

0

resize_to_limit只有在圖像大小大於指定值時纔會生效。在這裏閱讀文檔:link

你會使用resize_to_fil

+0

完美。想知道如何使圖像達到指定的尺寸 – 2015-02-28 15:24:47

相關問題