如何让图像显示尺寸为1030x150而不显眼?
我曾试图使用crop并填充载波,但它似乎没有用。目前,图像显示为一个大的方形图像,但我想裁剪图像,使其中心显示为页面顶部的长横幅。
谢谢!
这是我的图片上传代码:
class ImageUploader < CarrierWave::Uploader::Base
# Include RMagick or MiniMagick support:
# include CarrierWave::RMagick
include CarrierWave::MiniMagick
# Choose what kind of storage to use for this uploader:
storage :fog
# storage :fog
# Override the directory where uploaded files will be stored.
# This is a sensible default for uploaders that are meant to be mounted:
def store_dir
"uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
end
version :thumb do
process :resize_to_fit => [32, 32]
end
version :preview do
process :resize_to_fit => [256, 256]
end
version :full do
process :resize_to_fill => [1030, 150]
process crop: '1030x150+0+0'
end
def extension_white_list
%w(jpg jpeg gif png)
end
def crop(geometry)
manipulate! do |img|
img.crop(geometry)
img
end
end
end
显示横幅将显示在标题div中的页面:
<div id="products_div">
<div class="container">
<div class="header">
<%= image_tag @stone.image.full.url %>
<h1><%= @stone.name %></h1>
</div>
<% @stone.products.each do |product| %>
<div class="center-block">
<div class="col-lg-3">
<div class = "thumbnail row">
<%= link_to product do %>
<%= image_tag product.image.preview.url, :size => "224.98x178.66" %>
<% end %>
<p><%= product.name[0..25] + "..." %></p>
<p><%= number_to_currency(product.price, :unit => '$') %></p>
</div>
</div>
</div>
<% end %>
</div>
</div>
<% if current_admin %>
<%= link_to 'Edit', edit_stone_path(@stone) %> |
<%= link_to 'Back', admin_stones_path %>
<% end %>