2014-07-08 57 views
2

我有一個carrier-and-mini-magick在rails-3-2項目上安裝。 我正在爲上傳的svg圖像創建版本時遇到問題。 我上傳的代碼如下carrierwave minimagick轉換後的svg不兼容

class SVGUploader < CarrierWave::Uploader::Base 
    include CarrierWave::MiniMagick 
    storage :file 

    process resize_to_fit: [400, 400] 
    version :thumb do 
    resize_to_fit(140, 140) 
    end 

    def extension_white_list 
    [:svg] 
    end 

    def store_dir 
    @dir ||= if ENV['PARALLEL_TEST_GROUPS'] 
     "system/uploads/#{ENV['TEST_ENV_NUMBER']}/#{Rails.env}/#{model.class.to_s.underscore}/#{model.name}" 
    else 
     "system/uploads/#{Rails.env}/#{model.class.to_s.underscore}/#{model.id.to_s}" 
    end 
    end 
end 

的問題是當過我上傳任何SVG圖像,它需要很長的時間來轉換。當我嘗試顯示圖片時,瀏覽器不渲染它們。

有人遇到過這個問題嗎?請幫忙。

+0

SVG圖像似乎是依賴於瀏覽器。嘗試遵循這個[博客](http://jonathandean.com/2013/01/retina-screen-ready-using-vector-svg-images-and-still-supporting-crappy-browsers/)。這可能會解決您的問題。 – Himesh

+0

看起來像迷你magick生成svg作爲一個獨立的文件。這在瀏覽器中變得不兼容。 –

回答

2

我沒有SVG格式保存爲PNG

我解決這個問題遠:

class FileUploader < CarrierWave::Uploader::Base 
    include CarrierWave::MimeTypes 
    include CarrierWave::MiniMagick 

    process :set_content_type 

    version :super_thumb, :if => :is_picture? do 
    process :resize_to_fill => [50, 50] 
    end 

    protected 

    def is_picture?(picture) 
    return false if set_content_type(picture).include?('svg') 
    set_content_type(picture).include?('image') 
    end 
end 
+0

@waqarmirza這個答案是否正確? –

相關問題