获取"无法加载模块"尝试使用Rails / ImageMagick缩放图像时

时间:2018-01-22 19:48:35

标签: ruby-on-rails image resize imagemagick ruby-on-rails-5

我想缩放我通过表单上传的上传图片。我有一台Mac(High Sierra)并且正在使用Rails 5.我目前正在使用此代码和" rmagick"宝石来处理它

@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

没有任何错误,所以我不确定问题是什么。

编辑:为响应给出的ansewr,以下是我尝试运行"捆绑安装时发生的事情

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

1 个答案:

答案 0 :(得分:0)

似乎无法加载libpng模块。我建议您尝试从源代码重新安装imagemagick,然后重新安装并链接libpng

brew uninstall imagemagick
brew install imagemagick --build-from-source
brew uninstall libpng
brew install libpng
brew link libpng