0

MiniMagick을 사용하여 평방 썸네일 이미지를 표시하고 싶습니다.레일 4 : MiniMagick을 사용하여 사각형의 작은 이미지를 어떻게 표시합니까?

이미지는 표시되지만 사각형 모양으로 표시되지 않습니다.

image_uploader.rb

class ImageUploader < CarrierWave::Uploader::Base 
    . 
    . 
    . 
    include CarrierWave::MiniMagick 
    . 
    . 
    . 
    storage :file 
    . 
    . 
    . 
    def store_dir 
    "uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}" 
    end 
    . 
    . 
    . 
    version :thumb do 
    process :resize_to_limit => [150, 150] 
    end 
    . 
    . 
    . 
end 

보기 \ aritcles_article.html.erb

<li> 
    <% article.photos.each do |photo| %> 
     <%= image_tag(photo.image_url(:thumb).to_s) if photo.image? %> 
    <% end %> 
</li> 

보기 \ shared_article_form.html.erb

<%= form_for(@article) do |f| %> 
    <%= render 'shared/error_messages', object: f.object %> 
    <div class="field"> 
    <%= f.text_area :content, placeholder: "Compose new article..." %> 
    <%= f.fields_for :photos do |p| %> 
     <%= p.hidden_field :article_id %> 
     <%= p.label :image %> 
     <%= p.file_field :image %> 
     <% if p.object.image and p.object.image.file %> 
    <%= image_tag p.object.image.url %> 
     <p><%= p.object.image.file.filename %></p> 
     <% end %> 
    <% end %> 
    </div> 
    <%= f.submit "Post", class: "btn btn-large btn-primary" %> 
<% end %> 

모델 \ photo.rb

class Photo < ActiveRecord::Base 
    mount_uploader :image, ImageUploader 
    validates :image, presence: true 
end 

메시지 "양식에 오류가 1 개 있습니다." 그리고 jpg 파일을 제출하면 'shared/error_messages'에 다음과 같은 오류 메시지가 나타납니다.

  • Photos image Failed to manipulate with MiniMagick, maybe it is not an image? Original Error: mogrify.exe: unable to open image 255,': No such file or directory @ error/blob.c/OpenBlob/2643. mogrify.exe: no decode delegate for this image format 255,' @ error/constitute.c/ReadImage/555. mogrify.exe: unable to open image 255,': No such file or directory @ error/blob.c/OpenBlob/2643. mogrify.exe: no decode delegate for this image format 255,' @ error/constitute.c/ReadImage/555. mogrify.exe: unable to open image 0.0)': No such file or directory @ error/blob.c/OpenBlob/2643. mogrify.exe: unable to open module file C:\Program Files (x86)\ImageMagick-6.8.7-Q16\modules\coders\IM_MOD_RL_0)_.dll': No such file or directory @ warning/module.c/GetMagickModulePath/682. mogrify.exe: no decode delegate for this image format `0.0)' @ error/constitute.c/ReadImage/555.

답변

0

난 당신이있어 생각 하나 개 기능 해제 ->resize_and_pad :

version :thumb do 
    process :resize_and_pad => [150, 150] 
    end 

참고 : [150, 150, "#ffffff"]에 색상을 추가 할 수 있으며, 기본적으로 투명하게 될 것.

cut thumbnail to fit과 같은 내용을 추가로하려고하지 않는 한 resize_and_pad은 대부분 당신에게 적합하지 않습니다.

+0

신속한 답변을 보내 주셔서 감사합니다. 이미지를 제출할 때'resize_and_pad'를 사용하면 오류가 나타납니다. 위의 오류 메시지와 shared_article_form.html.erb를 업데이트했습니다. – SamuraiBlue

+0

** SOLVED ** minimagick 대신 include CarrierWave :: RMagick을 사용할 때 작동합니다. '버전 : thumb do process : resize_to_fill => [150, 150] end'. 브라이언 클락에게 고마워. – SamuraiBlue