2014-07-08 7 views
2

레일 스 -3-2 프로젝트에 mini-magick으로 캐리어 웨이브가 설치되어 있습니다. 업로드 된 svg 이미지의 버전을 만드는 데 문제가 있습니다. 내가 어떤 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 

를 다음과 같이 내 업 로더 코드입니다. 이미지 브라우저를 표시하려고 할 때 렌더링되지 않습니다.

누구든지이 문제에 직면 했습니까? 도와주세요. 내가

를 PNG로 형식 SVG없이 저장

+0

SVG 이미지는 브라우저에 의존하는 것 같다. 이 [블로그] (http://jonathandean.com/2013/01/retina-screen-ready-using-vector-svg-images-and-still-supporting-crappy-browsers/)를 따라 해보십시오. 이렇게하면 문제가 해결 될 수 있습니다. – Himesh

+0

mini magick이 독립 실행 형 파일로 svg를 생성하는 것처럼 보입니다. 어떤 브라우저에서 호환되지 않습니다. –

답변

2

나는이 멀리 해결 :

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이 답변이 맞습니까? –