gpt4 book ai didi

ruby-on-rails-3 - 在Rails 3中使用带有carreirwave的MiniMagick进行图像裁剪时出错

转载 作者:行者123 更新时间:2023-12-04 07:02:36 26 4
gpt4 key购买 nike

我正在尝试使用带有载波的 mini magick gem 裁剪图像。我在创建用户时面临以下问题。

Errno::ENOENT in UsersController#create

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

我的代码:
模型/用户.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

关于ruby-on-rails-3 - 在Rails 3中使用带有carreirwave的MiniMagick进行图像裁剪时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12492584/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com