Ruby on rails Ubuntu 14.04中的Carrierwave图像上载问题

Ruby on rails Ubuntu 14.04中的Carrierwave图像上载问题,ruby-on-rails,carrierwave,ubuntu-14.04,minimagick,Ruby On Rails,Carrierwave,Ubuntu 14.04,Minimagick,我在Ubuntu14.04 LTS上上传Carrierwave图像时遇到一些问题。每当我上传一个图像到服务器上,我都会遇到这个错误 ["Media Failed to manipulate with MiniMagick, maybe it is not an image? Original Error: Command (\"mogrify -resize x /tmp/mini_magick20141107-2577-xtam9r.jpg\") failed: {:status_code=&

我在Ubuntu14.04 LTS上上传Carrierwave图像时遇到一些问题。每当我上传一个图像到服务器上,我都会遇到这个错误

["Media Failed to manipulate with MiniMagick, maybe it is not an image? Original Error: Command (\"mogrify -resize x /tmp/mini_magick20141107-2577-xtam9r.jpg\") failed: {:status_code=>1, :output=>\"mogrify.im6: invalid argument for option `x': -resize @ error/mogrify.c/MogrifyImageCommand/5489.\\n\"}"]
这似乎不是一个小问题。我试着从控制台运行mimimaginks resize

uri = URI.parse /image_path
#<URI::HTTPS:0x0000000a446b28 URL:/image_path>

min = MiniMagick::Image.open uri
 => #<MiniMagick::Image:0x000000054c8420 @path="/tmp/mini_magick20141110-2176-2lzg9y.jpg", @tempfile=#<Tempfile:/tmp/mini_magick20141110-2176-2lzg9y.jpg>, @info={}, @command_queued=false, @queue=#<MiniMagick::CommandBuilder:0x000000054cf518 @tool="mogrify", @args=[]>>

min.resize "100x100"
=> true
注意:同样的代码适用于Ubuntu 13.10和我的开发机器Mac OSX 10.10。甚至几天前,它也曾在相同的14.04设置下工作。在apt得到更新后,一切都变得一团糟

这是我的图片上传器

# encoding: utf-8

class ImageUploader < CarrierWave::Uploader::Base

    # Include RMagick or MiniMagick support:
    include CarrierWave::MiniMagick
    # include CarrierWave::ImageOptimizer

    # Choose what kind of storage to use for this uploader:
    # storage :file
    storage :fog

    #before :cache, :retain_original_info
    #process :optimize

    # Add a white list of extensions which are allowed to be uploaded.
    # For images you might use something like this:
    def extension_white_list
        %w(jpg jpeg png)
    end

    # Override the directory where uploaded files will be stored.
    # This is a sensible default for uploaders that are meant to be mounted:
    def store_dir
        if Rails.env == "production"
            "gooru/stories/#{model.viewable_id}/res"
        else
            "test/gooru/stories/#{model.viewable_id}/res"
        end
    end

    #to create the versions in background
    def is_processing_delayed?(img = nil)
        @is_processing_delayed
    end

    def is_processing_delayed=(value)
        @is_processing_delayed = value
    end

    #to create the banner versions when the story is selected for reccommend/featured list in admin panel
    def is_live?(img = nil)
        @is_live
    end

    def is_live=(value)
        @is_live = value
    end

    # NOTE: Using resize to fill for sensitive images, incase the users don't listen to us :D 

    # => Use this for thumb images in read page 
    # => Maintain 4:3 ratio. Reduce qualitty in 90
    version :thumb  do
        #process :remove_animation
        process :resize_to_fill => [120, 90]
        process :convert => 'jpg'
        process :quality => 100
    end

    # => Maintain 4:3 ratio for image loading
    version :cover_new , :if => :is_live? do
        process :resize_to_fill => [242, 179]
        process :convert => 'jpg'
    end

    # => Use this for small thumb images in recommended stories.
    # => Maintain 4:3 ratio. Reduce qualitty in 90
    version :thumb_small   do
        #process :remove_animation
        process :resize_to_fit => [48, 36]
        process :convert => 'jpg'
        process quality: 50
        # process :quality => 50
    end

    # => maintain the aspect ratio of the image
    version :banner_new, :if => :is_live? do
        process :resize_to_fit => [342, 256]
        process :convert => 'jpg'
    end

    version :leftright do
        process :resize_to_fit => [667*2, 778*2], :if => :is_retina_resolution?
        process :resize_to_fit => [667, 778], :if => Proc.new {|version| !version.send(:is_retina_resolution?, nil)}
        process :quality => 100
    end

    version :updown do
        process :resize_to_fit => [1024*2, 487*2], :if => :is_retina_resolution?
        process :resize_to_fit => [1024, 487], :if => Proc.new {|version| !version.send(:is_retina_resolution?, nil)}
        process :quality => 100
    end

    version :original do
        process :original_dimensions
        process :quality => 100
    end

    #resize the original image to fit the default resolution 1024*768
    process :resize_to_fit => [1024*2, 768*2], :if => :is_retina_resolution?
    process :resize_to_fit => [1024, 768], :if =>  Proc.new {|version| !version.send(:is_retina_resolution?, nil)}


    def original_dimensions
        Rails.logger.info "Originall dimensions"
        if model.read_attribute(:media).present?
            Rails.logger.info "#{model.media.url}"
            img = MiniMagick::Image.open( model.media.url)
        else
            img = MiniMagick::Image.open(@file.file)
        end

        @@width = model.original_width
        @@height = model.original_height

        resize_to_fit @@width,@@height
    end

    # Override the filename of the uploaded files:
    # the file name is overridden with random hex number to handle uniqueness
    # and new origina_name colun is added to preserve the original name
    def filename
        if original_filename.present?
            if model && model.read_attribute(:media_filename).present?
                model.read_attribute(:media_filename)
            elsif model.read_attribute(:migration_name).present?
                model.read_attribute(:migration_name)
            else
                "#{secure_token(10)}.#{file.extension.downcase}"
            end
        end
    end

    def convert_to_grayscale
        manipulate! do |img|
            img.colorspace("Gray")
            #img.brightness_contrast("-30x0")
            img = yield(img) if block_given?
            img
        end
    end

    protected

    def secure_token(length=16)
        var = :"@#{mounted_as}_secure_token"
        model.instance_variable_get(var) or model.instance_variable_set(var, SecureRandom.hex(length/2))
    end


    def gif?(new_file)
        if self.file.content_type
            new_file.content_type.include? 'gif'
        else
            MIME::Types.type_for(model.read_attribute(:media)).first.to_s.include? 'gif'
        end
    end

    def is_retina_resolution?(new_file)
        if model.is_retina?.nil?
            image = MiniMagick::Image.open(self.file.file)
            @org_width = image[:width]
            @org_height = image[:height]
            if @org_height  >= 1536 and @org_width  >= 2048
                model.is_retina=  true
            else
                model.is_retina=  false
            end
        end
        model.is_retina?

    end

=begin
    def is_not_retina_resolution?(new_file)
        if model.is_retina?.nil?
            image = MiniMagick::Image.open(self.file.file)
            model.is_retina=  false if image[:height] < 1536 and image[:width] < 2048
        end
        model.is_retina?
    end
=end

    # Retain the original files meta information before we process it.
    def retain_original_info(file)
        # Sometimes, file.file doesn't have the tempfile object and it breaks the flow.
        begin
                image = MiniMagick::Image.open(file.path)
                Rails.logger.info model.original_width
                Rails.logger.info model.original_height
                model.original_width ||= image[:width]
                model.original_height ||= image[:height]
        rescue Exception => e

        end
        if file.respond_to?(:original_filename)
            model.original_filename ||= file.original_filename
        end
    end

=begin
    def secure_token(length=16)
        var = :"@#{mounted_as}_secure_token"
        model.instance_variable_get(var) or model.instance_variable_set(var, SecureRandom.hex(length/2))
    end
=end

    #to remove animation from a gif image This is useful when creating thumbnails
    def remove_animation
        manipulate! do |img, index|
            index == 0 ? img : nil
        end
    end



end
我使用ImageMagick版本

Version: ImageMagick 6.7.7-10 2014-03-06 Q16 http://www.imagemagick.org
Copyright: Copyright (C) 1999-2012 ImageMagick Studio LLC
Features: OpenMP
我比较了13.10服务器和新的14.04服务器中的所有gem。一切都一样。Imagemagick版本也相同

最后,我按照此处的指南重新安装了所有依赖项
.. 但这也没用

我完全不知道为什么会发生这种情况,也无法确定根本原因。请帮我做这个

source 'http://rubygems.org'
ruby '2.0.0'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.0.2'

gem 'sass-rails',   '~> 4.0.0' , :require => 'sass'
gem 'coffee-rails', '~> 4.0.0'
gem 'uglifier', '>= 1.3.0'
gem 'execjs'
gem 'therubyracer', :platforms => :ruby

#Analytics
#gem 'activemerchant', github: 'Shopify/active_merchant'
gem 'kaminari'

gem 'parse-ruby-client'

# See https://github.com/sstephenson/execjs#readme for more supported runtimes
# gem 'therubyracer', platforms: :ruby

# Use jquery as the JavaScript library
gem 'jquery-rails'

# Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks
gem 'turbolinks'

# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 1.2'

group :doc do
    # bundle exec rake doc:rails generates the API under doc/api.
    gem 'sdoc', require: false
end

# Use ActiveModel has_secure_password
# gem 'bcrypt-ruby', '~> 3.0.0'

# Use unicorn as the app server
# gem 'unicorn'

gem 'mongoid', github: 'mongoid/mongoid', tag: 'v4.0.0.alpha1'
gem 'mongoid-paranoia', github: 'Rameshv/mongoid-paranoia'

# gem 'flamegraph'
# gem 'rack-mini-profiler'

# todo implement this once the mongoid 4 branch is stable and merged with model name pull request
# gem 'mongoid-autoinc', github: 'suweller/mongoid-autoinc',branch: 'mongoid-4'
# implement this when collaborative editing added
# gem 'mongoid-history'
# gem 'mongoid_userstamp'

gem 'haml'
gem 'ejs'

gem 'carrierwave'
gem 'carrierwave-mongoid', :require => 'carrierwave/mongoid'
# gem 'carrierwave-imageoptimizer', '1.2.1'
gem 'mini_magick', '3.8.0'

# gem 'rmagick', '2.13.2', :require => 'RMagick'

gem 'validates_timeliness', '~> 3.0.2'
gem 'protected_attributes' #rails 4 attr_accessible & attr_protected 

# JSON manipulation
gem 'rabl', '~> 0.10.1'
gem 'oj', '~> 2.9.9'

gem 'devise','3.1.0'
gem 'oauth2'
gem 'ims-lti'
gem 'omniauth'  
# gem 'omniauth-facebook'
# gem 'omniauth-google-oauth2'
gem 'sitemap_generator'

#gem 'activeadmin',  github: 'gregbell/active_admin'
#gem 'activeadmin-mongoid', github: 'elia/activeadmin-mongoid', branch: 'rails4'
#gem 'activeadmin-mongoid', path: '../activeadmin-mongoid'


gem 'resque',  github: 'resque/resque' , branch: '1-x-stable'
gem 'resque_mailer', github: 'zapnap/resque_mailer'
gem 'resque-scheduler'
gem 'resque-logger'


#Font awesome gem
gem "font-awesome-rails"

gem 'rubyzip'
gem 'hpricot'

gem 'aws-sdk', '~> 1.0'

gem 'awesome_print', github:'michaeldv/awesome_print', branch: 'v2'
# gem "omnicontacts"

gem 'redis'
gem 'redis-namespace'
gem 'redis-rails'
gem 'redis-rack-cache'

group :production do
    gem 'passenger'
end
gem 'fog'

gem "capistrano-resque", "~> 0.2.1", require: false



group :development, :test do
    # server
    gem 'thin'
    #-->Testing
    #gem 'rspec'
    #gem 'rspec-rails', '~> 2.4'
    gem 'minitest'
    gem 'minitest-spec-rails'
    gem 'webrat'
    gem 'factory_girl'
    gem 'faker'
    gem 'rails-erd'
    gem 'railroady'
    gem 'wirble'

    gem 'rails-dev-boost', :git => 'git://github.com/thedarkone/rails-dev-boost.git'

    gem 'hirb'
    gem 'wirb'
    #gem 'coffee-rails-source-maps'

    # Rubymine coffeescript debugging
    #gem 'coffee-script-redux-debugger', git => 'git://github.com/JetBrains/coffee-script-redux-debugger.git'

    # Gives more info about errors
    gem 'better_errors'

    #logs for all the SQL queries and website status
    #gem 'rack-mini-profiler'

    gem 'guard'
    gem 'guard-livereload', require: false
    gem 'rack-livereload'

    gem 'capistrano', '~> 3.2.1'
    gem 'capistrano-rvm', git: 'git@github.com:capistrano/rvm.git'
    gem 'capistrano-bundler'
    gem 'capistrano-rails'
    gem 'commands'

    # gem "launchy", "~> 2.4.2"
    #Opens emails in browser
    # gem "letter_opener"
end
Version: ImageMagick 6.7.7-10 2014-03-06 Q16 http://www.imagemagick.org
Copyright: Copyright (C) 1999-2012 ImageMagick Studio LLC
Features: OpenMP