Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/56.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 使用回形针(或可能的imagemagick/mini_magick)将80%缩放视为100%缩放_Ruby On Rails_Imagemagick_Paperclip_Zooming_Minimagick - Fatal编程技术网

Ruby on rails 使用回形针(或可能的imagemagick/mini_magick)将80%缩放视为100%缩放

Ruby on rails 使用回形针(或可能的imagemagick/mini_magick)将80%缩放视为100%缩放,ruby-on-rails,imagemagick,paperclip,zooming,minimagick,Ruby On Rails,Imagemagick,Paperclip,Zooming,Minimagick,我最初学习了第三版的RubyonRails教程,用于Rails4()。在rails 5的第四版教程发布后,我更新了rails 5,更新了gemfile中的所有内容以匹配教程中提到的更改,略过了新教程中的差异,并在必要时进行了调整以修复问题 几乎所有的东西都能正常工作,但我调整了我的示例网站,这样用户就可以上传自己的头像,而不是依赖注册来上传头像。它们过去的工作原理与预期完全一致,但在更新所有内容后,80%缩放的图像将被视为100%缩放。我的意思是:我将中等大小的图像设置为184x184像素。如果

我最初学习了第三版的RubyonRails教程,用于Rails4()。在rails 5的第四版教程发布后,我更新了rails 5,更新了gemfile中的所有内容以匹配教程中提到的更改,略过了新教程中的差异,并在必要时进行了调整以修复问题

几乎所有的东西都能正常工作,但我调整了我的示例网站,这样用户就可以上传自己的头像,而不是依赖注册来上传头像。它们过去的工作原理与预期完全一致,但在更新所有内容后,80%缩放的图像将被视为100%缩放。我的意思是:我将中等大小的图像设置为184x184像素。如果将浏览器视图缩小到80%,化身将正确显示为184x184像素的图像。但是,如果在浏览器中保持默认的缩放级别,100%,则由于某些原因,它们的大小为230x230像素

经过大量的测试和调整,这是一个问题,我一直无法找出原因,或如何解决它。以下是负责处理用户化身的代码位,位于app/models/user.rb中:

  has_attached_file :avatar, :styles => { :tiny => "60x60!",
      :small  => "100x100!",
      :medium => "184x184!",
      :large => "200x200!" }, :default_url => "/assets/missing_:style.png",
  :convert_options => { :tiny => "-strip",
      :small => "-strip", 
      :medium => "-strip",
      :large => "-strip" }
  validates_attachment_content_type :avatar, content_type: /\Aimage\/.*\Z/
  validates_with AttachmentSizeValidator, attributes: :avatar, less_than: 2.megabytes

  before_post_process :check_file_size
  def check_file_size
    valid?
    errors[:avatar_file_size].blank?
    not avatar.size > 2.megabytes
  end
下面是关于上述格式中使用的感叹号的文档:(是的,我曾尝试使用反斜杠来保留感叹号,以防出现问题,但事实并非如此。)

这是我目前的gemfile,尽管我在试图弄清楚所有这些的时候已经改变了好几次:

source 'https://rubygems.org'
  gem 'rails', '5.0.0.1'
  gem 'bcrypt', '3.1.11'
  gem 'faker', '1.6.6'
  gem 'carrierwave', '0.11.2' # Image uploader in test environment
  gem 'mini_magick', '4.6.1' # Image resizing
  gem 'fog', '1.38.0' # Image uploader in production environment
  gem 'will_paginate', '3.1.0'
  gem 'bootstrap-will_paginate', '0.0.10'
  gem 'bootstrap-sass', '3.3.6'
  gem 'puma', '3.4.0'
  gem 'sass-rails', '5.0.6'
  gem 'uglifier', '3.0.0'
  gem 'coffee-rails', '4.2.1'
  gem 'jquery-rails', '4.1.1'
  gem 'turbolinks', '5.0.1'
  gem 'jbuilder', '2.4.1'
  gem 'paperclip', '5.1.0' # For avatar uploading
  gem 'simple_form', '3.2.1'

group :development, :test do
  gem 'sqlite3', '1.3.12'
  gem 'byebug', '9.0.0', platform: :mri
end

group :development do
  gem 'web-console',           '3.1.1'
  gem 'listen',                '3.0.8'
  gem 'spring',                '1.7.2'
  gem 'spring-watcher-listen', '2.0.0'
end

group :test do
  gem 'rails-controller-testing', '0.1.1'
  gem 'minitest-reporters', '1.1.9'
  gem 'guard', '2.13.0'
  gem 'guard-minitest', '2.4.4'
end

group :production do
  gem 'pg', '0.18.4'
end

# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]

以前有人遇到过这样的问题吗?

我注意到您在项目中同时使用了回形针和卡里瓦夫。我会尝试使用其中任何一种。我还建议在开始时只使用两种样式,以后当您发现问题所在时,可以添加更多样式。我在我的回形针项目中使用了下面这个简单的例子,这可能会帮助您:

has_attached_file :avatar, :styles => { :medium => "300x300>", :thumb => "100x100#" }, :default_url => "/images/:style/missing.png"
validates_attachment_content_type :avatar, :content_type => /\Aimage\/.*\Z/     
在导航栏中打印头像(摘自部分):

显然,我将缩略图裁剪为100x100,并用css缩小了头像的高度和宽度,以满足我的需要

好书:


希望能有所帮助

谢谢你的提示!加高度:147.5px;宽度:147.5px;img{宽度:100%};对于CSS样式,允许对其进行编辑,并以184x184像素显示图像。(147x147=184宽度和183[SIC]高度,148x148=185x185。编程背后的“逻辑”有时会超出我的想象,这就是其中之一。)我以前曾尝试添加高度:和宽度:作为编辑显示图像的一种手段,但显然它从未起作用,因为它缺少“img{width:100%}”行。哦,我忘了补充:根据你的建议,我也删除了carrierwave,并尝试了你在测试时提到的其他几件事情(例如,对我的image_tag@user等版本做了一些轻微的修改)。不客气!是的,当我们将“图像宽度”属性设置为100%时,图像将响应并缩放。我很高兴你解决了它!我们都在这里互相帮助:-)
<li class="avatar"><%= image_tag(current_user.avatar.url(:thumb)) %></li>
.avatar{
    background-color: white;
    border: 1px solid #d9d9d9;
    height: 60px;
    width: 60px;
    img { width: 100% }
}