我需要检查人们上传到我网站的图像是否具有 200 像素的确切宽度和 300 像素的高度。如果他们没有这些维度,则不应将它们保存在数据库中。
我已经用 mini-magick 尝试了很长时间,并浏览了许多教程、Stack Overflow 上的帖子等,但我找不到这样做的实用方法。
我在运行 mongoid 的 mongoDB 上使用 ruby 1.9.3 和 rails 3.2.2。
真的希望你能把我引向正确的方向。
我的图像模型如下所示:
class Flow
include Mongoid::Document
include Mongoid::Taggable
include Mongoid::Timestamps
include Mongo::Voteable
voteable self, :up => +1, :down => -1
attr_accessible :image, :remote_image_url, :tags
mount_uploader :image, UserUploader
belongs_to :user
field :shot, :type => String
field :remote_image_url, :type => String
field :tags, type: Array
end
我的载波模型如下所示:
class UserUploader < CarrierWave::Uploader::Base
include CarrierWave::MiniMagick
storage :fog
def store_dir
"uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
end
def extension_white_list
%w(jpg jpeg png gif)
end
end