我需要从 URL 加载图像(存储在 Amazon S3 存储桶中),从此图像创建缩略图并将其(新缩略图)上传到同一个 S3 存储桶。
过去 5 个小时,我试图在我的 Lion OSX 上安装 RMagick,但我的所有线程都从 RMagic 变灰。在 OSX 上安装 RMagick 似乎是不可能的。
因此,有没有其他方法可以做到这一点?
编辑:
在Gemfile
:宝石“rmagick”
错误:
uninitialized constant ImagesController::Magick
在控制器中:
def resize_images
require 'rubygems'
require 'RMagick'
include Magick
require "open-uri"
file_url = open('URL to image')
save_path = "/"
f = File.new( File.join(save_path, file_url), "wb")
f.write file_url.read
f.close
image = Magick::Image.read(file_url).first
image.change_geometry!("1500x150") { |cols, rows, img|
newimg = img.resize(cols, rows)
newimg.write("newfilename.jpg")
}
end
编辑2:
当我把它放入Gemfile
:
gem "rmagick", :require => 'RMagick'
捆绑它并运行服务器,我收到以下错误:
/Users/adam/.rvm/gems/ruby-1.9.3-p385@global/gems/bundler-1.2.3/lib/bundler/runtime.rb:197: warning: Insecure world writable dir /usr/local/mysql in PATH, mode 040777
/Users/adam/.rvm/gems/ruby-1.9.3-p385@global/gems/bundler-1.2.3/lib/bundler/runtime.rb:197: warning: Insecure world writable dir /usr/local/mysql in PATH, mode 040777
/Users/adam/.rvm/gems/ruby-1.9.3-p385@global/gems/bundler-1.2.3/lib/bundler/runtime.rb:68:in `require': cannot load such file -- RMagick (LoadError)
from /Users/adam/.rvm/gems/ruby-1.9.3-p385@global/gems/bundler-1.2.3/lib/bundler/runtime.rb:68:in `block (2 levels) in require'
from /Users/adam/.rvm/gems/ruby-1.9.3-p385@global/gems/bundler-1.2.3/lib/bundler/runtime.rb:66:in `each'
from /Users/adam/.rvm/gems/ruby-1.9.3-p385@global/gems/bundler-1.2.3/lib/bundler/runtime.rb:66:in `block in require'
from /Users/adam/.rvm/gems/ruby-1.9.3-p385@global/gems/bundler-1.2.3/lib/bundler/runtime.rb:55:in `each'
from /Users/adam/.rvm/gems/ruby-1.9.3-p385@global/gems/bundler-1.2.3/lib/bundler/runtime.rb:55:in `require'
from /Users/adam/.rvm/gems/ruby-1.9.3-p385@global/gems/bundler-1.2.3/lib/bundler.rb:128:in `require'
from /Users/adam/rubydev/looky/config/application.rb:9:in `<top (required)>'
from /Users/adam/.rvm/gems/ruby-1.9.3-p385/gems/railties-3.2.9/lib/rails/commands.rb:53:in `require'
from /Users/adam/.rvm/gems/ruby-1.9.3-p385/gems/railties-3.2.9/lib/rails/commands.rb:53:in `block in <top (required)>'
from /Users/adam/.rvm/gems/ruby-1.9.3-p385/gems/railties-3.2.9/lib/rails/commands.rb:50:in `tap'
from /Users/adam/.rvm/gems/ruby-1.9.3-p385/gems/railties-3.2.9/lib/rails/commands.rb:50:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'