我使用回形针来调整图片的大小,如下所示:
class Asset < ActiveRecord::Base
has_attached_file :asset, :styles => { :thumb => "80x80#",
:medium => "1280x800>" }, ...
当原图大小为
32x32
时:medium
图片大小相同(即 32x32
),但文件有点不同,图片看起来有点变化。这是为什么 ? thumb
大小为 80x80
(它看起来被拉伸(stretch)以适合这个尺寸)。图片太小时如何避免调整大小。假设原始图片的尺寸在
width
和 height
变量。 最佳答案
(1) 可能是因为 Paperclip 正在解码 JPEG,然后写入/编码新的 JPEG。 JPEG 是一种有损格式,因此每次编码都会降低图像质量。您可以使用 convert_options
调整JPEG quality但您可能不得不接受 JPEG 格式的一些劣化。
(2) 是因为 Paperclip 正在按照它的说法行事。 Paperclip 使用 ImageMagick 完成繁重的工作,样式尺寸仅为 ImageMagick geometry strings与 one modification :
Paperclip also adds the “#” option (e.g. “50x50#”), which will resize the image to fit maximally inside the dimensions and then crop the rest off (weighted at the center).
您的
:thumb
style 使用“#”,所以你告诉 Paperclip 你想要一个 80x80 的图像,即使图像必须被缩放和裁剪才能到达那里。您可以从维度字符串中删除“#”,如果需要或适当,添加 the other modifiers 之一.
关于ruby-on-rails - Paperclip:如何仅在图像足够大的情况下调整图像大小?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6729643/