2014-10-08 39 views
0

我對我的應用使用回形針,圖像不符合我設置的尺寸。我使用回形針和rmagick並安裝了ImageMagik。當我跑到哪裏轉換回形針沒有正確調整尺寸

C:\Program Files\ImageMagick-6.8.9-Q16\convert.exe 
C:\Windows\System32\convert.exe 

Development.rb

Paperclip.options[:command_path] = "C:/Program Files/ImageMagick-6.8.9-Q16/convert.exe" 

的Gemfile

gem 'paperclip' 
gem 'rmagick', '~> 2.13.2', :platforms => :ruby 

User.rb

has_attached_file :avatar, styles: { medium: '210x260>', larger: "300x300>", thumb: "100x100>" }, default_url: "/assets/default.png" 
validates_attachment_content_type :avatar, :content_type => ["image/jpg", "image/jpeg", "image/png", "image/gif"] 

視圖

<%= image_tag @user.avatar(**style**) %> 

我以不同的大小在兩個不同的圖像測試它,A(原:960x688)和B(最初:160x160的)

A(:拇指)變爲100x72

B( :拇指)變爲100×100

A(:介質)變爲210x151

B(:介質)變爲160×160

A(:大)成爲300x300的

B(:大)成爲300x300的

我試着重新上傳圖片後,我改變大小,但得到相同的結果。那麼,回形針有不同大小的圖像有問題,或者我的代碼有問題嗎?

+1

嘗試把一個#上,而不是一個> – Richlewis 2014-10-08 22:14:28

+0

該固定他們到底d再處理,將被調整,但我不得不上傳的圖片再次每次我改變了風格的時間。如果我必須改變其他地方的風格,我是否需要繼續上傳圖像? – teddybear 2014-10-08 22:28:13

回答

1

你需要你的尺寸大小後更改尾隨字符,所以你的情況,你需要

medium: 210x260# 

的文件中明確規定

Default behavior is to resize the image and maintain aspect ratio (i.e. the :medium version of a 300×150 image will be 200×100). Some commonly used options are: 

trailing '#', thumbnail will be centrally cropped, ensuring the requested dimensions. 
trailing '>', thumbnail will only be modified if it is currently larger requested dimensions. (i.e. the :small thumb for a 120×80 original image will be unchanged) 

對於當前的圖像您可以在此控制檯

Image.all.each {|s| s.image.reprocess! } 

之後,您上傳的任何其他圖片將不會被要求根據您的需要

希望幫助