So, I have 'thumbnails' of images on a page. The images are resized via CSS, hence the quotes on 'thumbnails'. Sometimes the images are tall, and sometimes they're wide. Obvious, right?
Right now, I'm handling this, but it's slow. Tell me there's a better way.
_photo.html.erb (partial to call <%= render '@photos' %>
)
<% image_size = FastImage.size(photo.image_url) %>
<% if image_size[0] > image_size[1] %>
<%= link_to image_tag(photo.image_url, class: 'wide'), photo if photo.image_url %>
<% else %>
<%= link_to image_tag(photo.image_url, class: 'tall'), photo if photo.image_url %>
<% end %>
and in the CSS...
img {
&.tall {
max-width: 220px;
min-width: 220px;
position: relative;
top: -20%;
left: -10px;
}
&.wide {
max-height: 220px;
min-height: 220px;
position: relative;
left: -20%;
top: -10px;
}
}
I already said, it works. When I call that page, though, it has to think about it, and there are only 3 photos. Obviously not a good solution. I'd also like to center the image in it's little 200px containter. My way just feels so... crude.
Thoughts?