我在rails-3-2项目上安装了一个带有mini-magick的载波。 我在为上传的 svg 图像创建版本时遇到问题。 我的 uploader 代码如下
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 图像时,转换都需要很长时间。当我尝试显示图像时,浏览器不会渲染它们。
有人遇到过这个问题吗?请帮忙。
最佳答案
我没有将 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
关于ruby-on-rails-3 - rierwave minimagick 转换的 svg 不兼容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24626796/