2016-09-10 16 views
0

画像を伸ばすことなく1030x150のサイズで表示するにはどうすればよいですか?Rails:Carrierwave作物と塗りつぶし

私は作物を使ってキャリヤーウェーブでいっぱいにしようとしましたが、動作していないようです。現在、画像は1つの大きな正方形の画像として表示されていますが、画像の中央がページの上部に長いバナーとして表示されるように画像をトリミングしたいと考えています。

ありがとうございます!ここで

が私の画像アップローダーコードです:バナーは、ヘッダーのdivに表示されます

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 

表示ページ:https://github.com/imgix/imgix-rails

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

答えて

0

これはあなたがお役に立てば幸いです。 それは私のために働く。

+0

リンクについての最小限の説明/コードを追加してください – HDJEMAI

+0

ありがとう、これは私が探していたものです。 – Kris