【发布时间】:2018-01-22 19:48:35
【问题描述】:
我想缩放通过表单上传的上传图片。我有一台 Mac(High Sierra)并且正在使用 Rails 5。我目前正在使用此代码和“rmagick”gem 来处理它
@person = Person.new(person_params)
if @person.image
cur_time_in_ms = DateTime.now.strftime('%Q')
file_location = "/tmp/file#{cur_time_in_ms}.ext"
File.binwrite(file_location, @person.image.read)
file = File.open(file_location, "rb")
contents = file.read
# Scale image appropriately
img = Magick::Image::read(file_location).first
@person.image = img.resize_to_fit(1000000, Rails.configuration.max_img_height)
但是当我上传图片时,我得到了错误
unable to load module `/usr/local/Cellar/imagemagick/6.9.2-4/lib/ImageMagick//modules-Q16/coders/png.la': file not found @ error/module.c/OpenModule/1300
上线
img = Magick::Image::read(file_location).first
我跑了
brew update && brew install imagemagick
没有任何错误,所以我不确定问题是什么。
编辑:响应给出的答案,这是我尝试运行“捆绑安装”时发生的情况
checking for presence of MagickWand API (ImageMagick version >= 6.9.0)... no
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of necessary
libraries and/or headers. Check the mkmf.log file for more details. You may
need configuration options.
Provided configuration options:
--with-opt-dir
--with-opt-include
--without-opt-include=${opt-dir}/include
--with-opt-lib
--without-opt-lib=${opt-dir}/lib
--with-make-prog
--without-make-prog
--srcdir=.
--curdir
--ruby=/usr/local/Cellar/ruby/2.4.2_1/bin/$(RUBY_BASE_NAME)
extconf.rb:104:in ``': No such file or directory - MagickWand-config (Errno::ENOENT)
from extconf.rb:104:in `configure_compile_options'
from extconf.rb:16:in `initialize'
from extconf.rb:548:in `new'
from extconf.rb:548:in `<main>'
To see why this extension failed to compile, please check the mkmf.log which can be found here:
/Users/nataliab/.rvm/gems/ruby-2.4.0/extensions/x86_64-darwin-17/2.4.0/rmagick-2.16.0/mkmf.log
extconf failed, exit code 1
Gem files will remain installed in /Users/nataliab/.rvm/gems/ruby-2.4.0/gems/rmagick-2.16.0 for inspection.
Results logged to /Users/nataliab/.rvm/gems/ruby-2.4.0/extensions/x86_64-darwin-17/2.4.0/rmagick-2.16.0/gem_make.out
An error occurred while installing rmagick (2.16.0), and Bundler cannot continue.
Make sure that `gem install rmagick -v '2.16.0'` succeeds before bundling.
In Gemfile:
rmagick
【问题讨论】:
-
你的路径中有一个双
//.. : ImageMagick//modules-Q16 -
看看这个链接:Using Image Magick with rails - 他说的是设置一些环境变量来安装gem。也许这就是问题所在(请注意 - 文章已有 10 年历史)
-
你需要控制器顶部的宝石,对吧?
-
该错误可能是由多种问题引起的。您可以尝试删除 rmagick
gem remove rmagick,然后使用 x11 安装 imagemagick,即brew install imagemagick --with-x11并重新安装 rmagick -
@Dipil,谢谢您的建议,但尝试这样做会导致相同的错误。我什至在运行 brew install 然后重新安装 gems 后重新启动了整个系统。
标签: ruby-on-rails image resize imagemagick ruby-on-rails-5