Paperclip忽略图像大小选项

时间:2015-10-18 19:12:54

标签: ruby-on-rails image paperclip

所以我在我的项目中设置了Paperclip gem设置来处理名为Story的模型的封面图像:

class Story < ActiveRecord::Base
    ...
    has_attached_file :cover_image,
                      styles: { large: "700x700>", thumb: "300x300>" },
                      default_url: "#{Rails.root}/app/assets/images/default_image.jpg",
                      path:"/cover_images/:filename",
                      processors: [:thumbnail, :paperclip_optimizer]

当我以小格式显示故事时,我试图使用thumb样式,如下所示:

<div class="image">
    <%= image_tag story.cover_image.url(:thumb) %>
</div>

Small Image Format

Paperclip documentation表示您应该指定要使用的样式。

在此上下文中,图像的正确尺寸为300x111px。

然而,当我移动到我的故事页面时,我想要图像的大/全尺寸版本:

<div class="header_image">
    <%= image_tag(@story.cover_image.url(:large)) %>

除了回形针错误仍然使用图像的缩略图版本:

Incorrect sizing

Low Resolution

为什么Paperclip没有正确调整图像大小?

1 个答案:

答案 0 :(得分:0)

您必须在:style中指定path选项:

has_attached_file :cover_image,
                      styles: { large: "700x700>", thumb: "300x300>" },
                      default_url: "#{Rails.root}/app/assets/images/default_image.jpg",
                      path:"/cover_images/:filename/:style",
                      processors: [:thumbnail, :paperclip_optimizer]

现在,Paperclip将上传不同版本的图像并根据需要访问它们:

Style options

Large image being used

相关问题