加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

ruby-on-rails-3 – 在Rails 3中使用带有carreirwave的MiniMagic

发布时间:2020-12-17 02:14:08 所属栏目:百科 来源:网络整理
导读:我正在尝试使用带有载波的迷你魔法宝石来裁剪图像.我正在创建用户时遇到以下问题. Errno::ENOENT in UsersController#createNo such file or directory - identify -ping /tmp/mini_magick20120919-5600-ai31ph.jpg 我的代码: 模型/ user.rb class User Act
我正在尝试使用带有载波的迷你魔法宝石来裁剪图像.我正在创建用户时遇到以下问题.

Errno::ENOENT in UsersController#create

No such file or directory - identify -ping /tmp/mini_magick20120919-5600-ai31ph.jpg

我的代码:
模型/ user.rb

class User < ActiveRecord::Base

  attr_accessor :crop_x,:crop_y,:crop_h,:crop_w
    attr_accessible :username,:profile
  after_update :reprocess_profile,:if => :cropping?

  #field :username

  mount_uploader :profile,ProfileUploader

  def cropping?
    !crop_x.blank? and !crop_y.blank? and !crop_h.blank? and !crop_w.blank?
  end

  def profile_geometry
    #img = MiniMagick::Image.open(self.profile.large.path)
    #@geometry = {:width => img[:width],:height => img[:height] }
  end

  private

  def reprocess_profile
    #puts self.profile.large.path
    #img = MiniMagick::Image.open(self.profile.large.path)
    #crop_params = "#{crop_w}x#{crop_h}+#{crop_x}+#{crop_y}"
    #img.crop(crop_params)
    #img.write(self.profile.path)
    #profile.recreate_versions!
  end

end

上传/ profile_uploader.rb

# encoding: utf-8

class ProfileUploader < CarrierWave::Uploader::Base

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

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

  # 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
    "uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
  end

  def extension_white_list
   %w(jpg jpeg gif png)
  end

  version :large do
  end

  version :thumb do
    process :resize_to_fill => [100,100]
  end

end

会出现什么问题?请提出任何解决方案.

解决方法

需要安装imagemagick.
在ubuntu中:

sudo apt-get install imagemagick

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读