尝试使用 Rails / ImageMagick 缩放图像时获得"unable to load module"



我想缩放通过表单上传的上传图像。 我有一台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

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

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

相关内容

最新更新