Ruby on rails 回形针尺寸不正确

Ruby on rails 回形针尺寸不正确,ruby-on-rails,ruby,ruby-on-rails-4,paperclip,Ruby On Rails,Ruby,Ruby On Rails 4,Paperclip,我正在为我的应用程序使用回形针,图像与我设置的大小不一致。我正在使用回形针和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/co

我正在为我的应用程序使用回形针,图像与我设置的大小不一致。我正在使用回形针和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"]
看法


我正在两个不同大小的不同图像上测试它,A(原来是960x688)和B(原来是160x160)

A(:拇指)变为100x72

B(:拇指)变为100x100

A(:中)变为210x151

B(:中等)变为160x160

A(:更大)变为300x300

B(:更大)变为300x300


我尝试在更改大小后重新上传图像,但得到相同的结果。那么,回形针对不同尺寸的图像有问题吗?或者我的代码有问题吗?

您需要在尺寸尺寸后更改尾随字符,因此在您的情况下,您需要

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! }
之后,您上传的任何其他图像将不需要重新处理,并将根据需要调整大小


希望这有帮助

试着在末尾加一个#而不是一个>来修复它们,但是每次我改变样式时都必须再次上传图像。如果必须的话,我会在其他地方更改样式时继续上传图像吗?
Image.all.each {|s| s.image.reprocess! }