我希望能够验证图像是完全确定的或具有一定的高度,或者如果它是方形的。你如何验证attachment_fu的图像宽度和高度?
在模型has_attachment
,的验证模块,当我尝试访问image_size
,width
,或height
,它永远是空。
我还问了here如果你想了解更多的细节。
我希望能够验证图像是完全确定的或具有一定的高度,或者如果它是方形的。你如何验证attachment_fu的图像宽度和高度?
在模型has_attachment
,的验证模块,当我尝试访问image_size
,width
,或height
,它永远是空。
我还问了here如果你想了解更多的细节。
是啊,你需要破解了一下,以得到它的工作,但没有这么多。从attachment_fu自己的图像处理器适应:
validate :validate_image_size
private
def validate_image_size
w, h = width, height
unless w or h
with_image do |img|
w, h = img.columns, img.rows
end
end
errors.add(:width, "must less than 250px") if w > 250
errors.add(:height, "must less than 250px") if h > 250
end
end
感谢马科斯,这看起来很有希望。我会尝试一下! – 2009-09-13 00:39:18
您尚未指定您正在处理的语言和系统。
但是,对于大多数Web框架,我认为使用image magic来实现这一点的标准方法。试试identify function.。
啊,我很抱歉。我在Ruby on Rails中使用attachment_fu插件。我使用迷你magick作为我的处理器。不过,根据你的评论,似乎我需要挖掘attachment_fu。 – 2009-02-01 03:30:45
你看过迷你魔术师吗?
你可以克隆它从这里的git:
http://github.com/probablycorey/mini_magick/tree/master
如果您需要了解git的,请查看以下链接:
http://git.or.cz/course/svn.html(速成班使用Git,相比颠覆)
http://github.com/guides/git-screencasts(github screencasts)
这是一个红宝石包装纸nd imagemagick函数(不确定attachment_fu是否在内部使用这个函数),但它绝对比RMagick好得多(RMagick非常臃肿,大量内存问题)。任何人,迷你magick会让你做所有你需要的东西,然后一些。查看上面的github链接中列出的自述文件,它会给你如何使用它的简介。
这里有一个片段:
#For resizing an image
image = MiniMagick::Image.from_file("input.jpg")
image.resize "100x100"
image.write("output.jpg")
#For determining properties of an image...
image = MiniMagick::Image.from_file("input.jpg")
image[:width] # will get the width (you can also use :height and :format)
我认为你缺少应该安装才能使用attachment_fu用于调整图像的前提宝石。我曾与attachment_fu插件,它是依赖于以下宝石
工作rmagick-2.11.0
image_science-1.2.0
确保已安装上述宝石和更改到has_attachment中的宽度和高度,然后您可以看到更改。
祝你好运!
对不起,我不回复一段时间 - 我没有检查那件事通过电子邮件更新我。 – 2009-09-13 00:37:38