【发布时间】:2013-08-20 17:14:33
【问题描述】:
我正在尝试在使用 Carrierwave 调整图像大小时优化图像,但没有任何运气让它发挥作用。 Carrierwave 正在生成不同大小的版本,但我的自定义优化和转换过程没有运行。我试过在不同的地方调用不同的进程,但似乎没有任何效果。
关于我可能做错的任何想法?会不会是同样的问题:CarrierWave RMagick - How do I cause manipulate! to be called?
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
【问题讨论】:
-
你的意思是优化调整大小的图像
-
是的,我希望将版本转换为 jpg,隔行扫描并调整到指定的尺寸。
-
我收到错误:
NameError (undefined local variable or method img你在哪里定义img? -
要操作的块得到一个变量。上面的示例已更新。