MiniMagick 隔行扫描不工作

MiniMagick Interlace isn't working

我有一些使用 MiniMagick 调整图像大小的自定义方法

def resize_to_limit(dimensions, degrade = false)
  width, height = dimensions
  MiniMagick::Image.open(current_path).tap do |image|
    image.resize "#{width}x#{height}>"
    image.combine_options do |cmd|
      if degrade
        cmd.quality 50
      end
      cmd.alpha 'remove'
      cmd.auto_orient
      cmd.interlace 'plane'
    end
    image.format('jpg')
    image.write current_path
  end
end

当我使用 identify 检查生成的图像时,Interlace 仍然是 None。不确定库是否更改了输入值,但我已经尝试了 Planeplane.

我尝试使用 Metal interface:

转换图像
require 'mini_magick'

MiniMagick::Tool::Convert.new do |convert|
  convert << "input.jpg"
  convert << "-interlace plane"
  convert << "output.jpg"
end

这应该相当于:

$ convert input.jpg -interlace plane output.jpg

实际上该命令按预期工作:

$ magick identify -verbose input.jpg output.jpg | grep Interlace
  Interlace: None
  Interlace: JPEG

您可以通过打开调试查看您的代码发出的命令:

MiniMagick.configure do |config|
  config.debug = true
end

当我 运行 你的代码打开调试时,我得到了一堆正在处理临时文件的命令:

MiniMagick.debug is deprecated and will be removed in MiniMagick 5. Use `MiniMagick.logger.level = Logger::DEBUG` instead.
D, [2017-05-17T23:30:28.456080 #12301] DEBUG -- : [0.01s] identify /var/folders/dh/_zgl_f_s0t7b4wk9j27cpny80000gp/T/mini_magick20170517-12301-17vo4b8.jpg
D, [2017-05-17T23:30:28.468335 #12301] DEBUG -- : [0.01s] mogrify -resize 500x500> /var/folders/dh/_zgl_f_s0t7b4wk9j27cpny80000gp/T/mini_magick20170517-12301-17vo4b8.jpg
D, [2017-05-17T23:30:28.481606 #12301] DEBUG -- : [0.01s] mogrify -alpha remove -auto-orient -interlace plane /var/folders/dh/_zgl_f_s0t7b4wk9j27cpny80000gp/T/mini_magick20170517-12301-17vo4b8.jpg
D, [2017-05-17T23:30:28.493634 #12301] DEBUG -- : [0.01s] convert /var/folders/dh/_zgl_f_s0t7b4wk9j27cpny80000gp/T/mini_magick20170517-12301-17vo4b8.jpg[0] /var/folders/dh/_zgl_f_s0t7b4wk9j27cpny80000gp/T/mini_magick20170517-12301-hks8tq.jpg

有一件事我不能不注意到 in the documentation 是行:

On the other hand, if we want the original image to actually get modified, we can use MiniMagick::Image.new.

所以也许可以尝试 new 而不是 open。然后观察调试输出以查看命令是否有意义。

看来您的代码过于复杂了?同样来自 the documentation:

As a handy shortcut, MiniMagick::Image.new also accepts an optional block which is used to combine_options.

所以如果使用 new.

,也许您不需要显式调用 combine_options