获得“无法加载模块”尝试使用Rails / ImageMagick缩放图像时 [英] Getting "unable to load module" when trying to scale image with Rails / ImageMagick

查看:207
本文介绍了获得“无法加载模块”尝试使用Rails / ImageMagick缩放图像时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I want to scale an uploaded image that I'm uploading through a form. I have a Mac (High Sierra) and am using Rails 5. I'm currently using this code and the "rmagick" gem to handle it

@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)

但是当我上传图片时,我收到错误

but when I upload the image, I get the error

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

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

without any errors so I'm not sure what the issue is.

编辑:为了回应ansewr,这是我尝试运行捆绑安装时发生的事情

In response to the ansewr given, here's what happened when I tried to run a "bundle install

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

It seems that the libpng module cannot be loaded. I would suggest trying to reinstall imagemagick from source, and then reinstall and link libpng.

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

这篇关于获得“无法加载模块”尝试使用Rails / ImageMagick缩放图像时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆