【问题标题】:PaperClip ruby on rails inconsistent image sizing on uploadPaperClip ruby​​ on rails 上传时图像大小不一致
【发布时间】:2015-02-11 11:47:51
【问题描述】:

我在 ruby​​ on rails 中使用 PaperClip 来处理模型的图像上传。除了对图像尺寸的处理不一致之外,它运行良好。

看这个例子:

看到最右边的图片比中间和左边的图片大了吗?

我需要确定发生这种情况的原因。

这是我的开发回形针配置:

#Paperclip storage locally and specify location of imagemagick
Paperclip.options[:command_path] = "/usr/local/bin/"
PAPERCLIP_STORAGE_OPTS = {
     :styles => { :thumb => '100x100#', :medium => '450x300>', :large => '600x400>'},
     :convert_options => { :all => '-quality 100' },
     :processor       => [ :cropper ]
   }
  # Raises error for missing translations
  # config.action_view.raise_on_missing_translations = true
end

我正在使用以下代码显示这些图像:

<div class="container">
<% count = 0 %>
<% results.each do |event| %>
<% if count == 3 %>
  <div class="row"></div>
<% end %>
<div class="col-xs-12 col-md-4">
<ul class="deals">
<li class="impression">
<%= link_to(event) do %>
<%= image_tag event.logo.url(:medium) %>
<div>
<h2><%= event.className %></h2>
<div><%= event.company_name %></div>
<table>
<tbody>
<tr>
<td>
<span>£<%= event.ppt %></span> 
£<%= event.ppc %></td>
<td>4 bought</td>
</tr>
</tbody>
</table>
</div>
<% end %>
</li>
</ul>
</div>
<% count = count +1 %>
<% end %>
</div>

当我在呈现 HTML 后调查实际的 img 大小时,它们如下所示:

网球图片:334 x 209(原始图像尺寸为 1024 x 640)

计算机训练图片:334 x 209(原始图像尺寸为 1600 x 1000)

Zumba 图片:334 x 223(原始图像尺寸为 1280 x 854)

由于某种原因,尊巴舞图片比其他图片长 14 像素?!为什么会发生这种情况 - 为什么 Paperclip 在此配置中不能一致地调整大小?还是与页面的css有关?!

【问题讨论】:

    标签: css ruby-on-rails paperclip


    【解决方案1】:

    答案是忽略 imagemagick 中的纵横比:

    http://www.imagemagick.org/Usage/resize/#noaspect

    因此我将配置选项更改为:

    #Paperclip storage locally and specify location of imagemagick
    Paperclip.options[:command_path] = "/usr/local/bin/"
    PAPERCLIP_STORAGE_OPTS = {
         :styles => { :thumb => '100x100!#', :medium => '450x300!>', :large => '600x400!>'},
         :convert_options => { :all => '-quality 100' },
         :processor       => [ :cropper ]
       }
      # Raises error for missing translations
      # config.action_view.raise_on_missing_translations = true
    end
    

    注意!在已添加的 '100x100!#' 中 - 这就是告诉 imagemagick 忽略纵横比的原因 - 这就是我在添加 ! 之前图像大小不一致的原因。

    哇哦。 ! .

    【讨论】:

      猜你喜欢
      • 2019-08-22
      • 2014-07-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-12-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多