仅当图像大于版本大小时,才可以使用载波创建版本(例如拇指)吗?
Example:
version :thumb, :if => :is_thumbnable? do
process :resize_to_fit => [32,nil]
end
protected
def is_thumbnable?(file)
image ||= MiniMagick::Image.open(file.path)
if image.nil?
if image['width'] >= 32 || image['height'] >= 32
true
else
false
end
else
false
end
end
我尝试过它们,但它对我不起作用。
在开发中调整为大图像时,我的服务器被阻塞。
- 载波 (0.9.0)
- rmagick (2.13.2)
所以我看了一下文档:http://rierwave.rubyforge.org/rdoc/classes/CarrierWave/RMagick.html http://carrierwave.rubyforge.org/rdoc/classes/CarrierWave/RMagick.html
有一个奇妙的功能:resize_to_limit(width, height)
调整图像大小以适合指定尺寸,同时保留原始纵横比。仅当图像大于指定尺寸时才会调整图像大小。生成的图像可能比较小尺寸中指定的更短或更窄,但不会大于指定的值。
我的代码如下所示:
version :version_name, from_version: :parent_version_name do
process resize_to_limit: [width, nil]
end
仅当宽度较大时,它才会调整大小以适应宽度,并考虑宽/高的比率。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)