我正在尝试在使用 Carrierwave 调整图像大小时优化图像,但没有任何运气让它发挥作用。Carrierwave 正在生成不同大小的版本,但我的自定义优化和转换过程没有运行。我试过在不同的地方调用不同的进程,但似乎没有任何效果。
关于我可能做错了什么的任何想法?这里可能是同样的问题:CarrierWave RMagick - 我如何引起操纵!被称为?
class FooUploader < CarrierWave::Uploader::Base
include CarrierWave::MiniMagick
# Attempt #1
process :convert => 'jpg'
process :optimize
version :meow do
process :resize_to_fill => [700, 400]
end
# Attempt #2
version :meow do
process :convert => 'jpg', :optimize => nil, :resize_to_fill => [700, 400]
end
# Attempt #3
version :meow do
process :resize_to_limit => [700, 400]
process :optimize
process :convert => 'jpg'
end
# Attempt #4
# Tried switching order around since they are being resized but not converted
version :meow do
process :convert => 'jpg'
process :optimize
process :resize_to_limit => [700, 400]
end
# Optimize method used by all versions
def optimize
manipulate! do |img|
img.strip
img.combine_options do |c|
c.quality "96"
c.depth "24"
c.interlace "plane"
#c.interlace "Plane" # Tried both cases, seen examples of both
end
img
end
end
end