简体   繁体   中英

PaperClip ruby on rails inconsistent image sizing on upload

I am using PaperClip in ruby on rails to handle image uploading for a model. It is working well apart from an inconsistent handling of image sizes.

See this example:

在此输入图像描述

See how the picture on the far right is larger than the pictures in the middle and on the left?

I need to identify why this is happening.

This is my development paperclip configuration:

#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

And I am showing these images using the following bit of code:

<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>

When I investigate the actual img sizes after the HTML is rendered they are as follows:

Tennis pic : 334 x 209 (Original image size is 1024 x 640)

Computer Training pic : 334 x 209 (Original image size is 1600 x 1000)

Zumba pic : 334 x 223 (Original image size is 1280 x 854)

For some reason the Zumba picture is 14 pixels longer than the others?! Why is this happening - why is Paperclip not resizing consistently in this configuration? Or is it to do with the css for the page?!

The answer was to ignore the aspect ratio in imagemagick as per :

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

I therefore changed the configuration options to be :

#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

Note the ! in the '100x100!#' which has been added - this is what tells imagemagick to ignore the aspect ratio - which was the reason I was having inconsistently sized images before I added the !.

Wahoo. ! .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM