我正在使用CarrierWave为我上传的图像添加版本。 resize_to_fit正在调整图像的大小以适应指定的尺寸,同时保留原始宽高比。如何在不保留原始宽高比的情况下调整图像大小,也不能裁剪它们?
您需要使用Carrierwave的manipulate!
方法在上传器中定义自定义处理方法。这是我刚刚测试过的一个例子:
class Uploader < CarrierWave::Uploader::Base
include CarrierWave::MiniMagick
storage :file
process :force_resize => [160, 160]
def force_resize(width, height)
manipulate! do |img|
img.resize("#{width}x#{height}!")
img
end
end
end
这会将图像大小调整为160x160px,而无需考虑宽高比(请注意resize
参数末尾的感叹号)。