显示的回形针图像尺寸不一致?

Paperclip image sizes not consistent in display?

这是我显示图像并发现它们不一致的方式。我分别在模型中创建了两个键:thumb 和 :test。

<% @posts.each do |post|%>
    <div class="panel panel-default">
        <div class="panel-heading">
            <h3 class="panel-title"><%= image_tag post.user.avatar.url(:thumb), class:"img-thumbnail" %>
                <%= image_tag post.user.avatar.url(:test), class:"img-thumbnail" %></br>
                 <%= post.user.name %>
            </h3>
        </div>
      <div class="panel-body">
        <%= post.content %></br>
        <%= image_tag post.avatar.url(:medium) %></br>
      </div>
    </div>
<% end %>

我的用户模型 如您所见,我指定了尺寸,但图像并未限制在这些范围内。我很困惑为什么要在模型中设置这些尺寸。

class User < ActiveRecord::Base
  # Include default devise modules. Others available are:
  # :confirmable, :lockable, :timeoutable and :omniauthable
  devise :database_authenticatable, :registerable,
         :recoverable, :rememberable, :trackable, :validatable

  validates :name, presence: true
  has_many :posts

  has_attached_file :avatar, 
                                    styles: { medium: "300x300>", thumb: "100x100>", test: "64x64>" }, 
                                    default_url: "/images/:style/missing.png"
  validates_attachment_content_type :avatar, content_type: /\Aimage\/.*\Z/
end

在您的模型中,您已将大小指定为 100X100>> 操作只会缩小大于 100 像素的图像并保持纵横比。

如果您希望图像恰好是 100X100 像素,请在不使用 > 运算符的情况下设置模型。

Paperclip 使用 Imagemagick 调整图像大小,您可以阅读更多相关信息 here