【问题标题】:carrierwave minimagick converted svg not compatible载波 minimagick 转换的 svg 不兼容
【发布时间】:2014-07-08 08:14:49
【问题描述】:

我在 rails-3-2 项目中安装了带有 mini-magick 的载波。 我在为上传的 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 图片时,转换需要很长时间。当我尝试显示图像时,浏览器不会呈现它们。

有人遇到过这个问题吗?请帮忙。

【问题讨论】:

  • SVG 图像似乎依赖于浏览器。尝试关注此blog。这可能会解决您的问题。
  • 似乎 mini magick 将 svg 生成为独立文件。这在浏览器中变得不兼容。

标签: ruby-on-rails-3 svg carrierwave minimagick


【解决方案1】:

我将没有格式的 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

【讨论】:

    猜你喜欢
    • 2020-03-26
    • 1970-01-01
    • 2011-05-15
    • 2011-12-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-05-28
    相关资源
    最近更新 更多