将拇指图像存储到paperclip gem中的特定目录

时间:2015-06-17 07:07:52

标签: ruby-on-rails ruby imagemagick paperclip paperclip-validation

这是代码

  has_attached_file :image,
                        :path => ":rails_root/public/images/:id/:filename",
                        :url  => "/images/:id/:filename",
                        :styles => { :small => "300x168>", :large => "1000x560>" }

这是我的控制台日志

Command :: PATH=/opt/imagemagick-6.9/bin:$PATH; file -b --mime '/tmp/2251fc5821941d6bd28b2ee3cb25bf7620150617-13080-1gg7ekt.png'
Command :: PATH=/opt/imagemagick-6.9/bin:$PATH; identify -format '%wx%h,%[exif:orientation]' '/tmp/2251fc5821941d6bd28b2ee3cb25bf7620150617-13080-197v1bm.png[0]' 2>/dev/null
Command :: PATH=/opt/imagemagick-6.9/bin:$PATH; identify -format %m '/tmp/2251fc5821941d6bd28b2ee3cb25bf7620150617-13080-197v1bm.png[0]'
Command :: PATH=/opt/imagemagick-6.9/bin:$PATH; convert '/tmp/2251fc5821941d6bd28b2ee3cb25bf7620150617-13080-197v1bm.png[0]' -auto-orient -resize "300x168>" '/tmp/2251fc5821941d6bd28b2ee3cb25bf7620150617-13080-197v1bm20150617-13080-8q41x9'
Command :: PATH=/opt/imagemagick-6.9/bin:$PATH; file -b --mime '/tmp/2251fc5821941d6bd28b2ee3cb25bf7620150617-13080-197v1bm20150617-13080-8q41x9'
Command :: PATH=/opt/imagemagick-6.9/bin:$PATH; identify -format '%wx%h,%[exif:orientation]' '/tmp/2251fc5821941d6bd28b2ee3cb25bf7620150617-13080-197v1bm.png[0]' 2>/dev/null
Command :: PATH=/opt/imagemagick-6.9/bin:$PATH; identify -format %m '/tmp/2251fc5821941d6bd28b2ee3cb25bf7620150617-13080-197v1bm.png[0]'
Command :: PATH=/opt/imagemagick-6.9/bin:$PATH; convert '/tmp/2251fc5821941d6bd28b2ee3cb25bf7620150617-13080-197v1bm.png[0]' -auto-orient -resize "1000x560>" '/tmp/2251fc5821941d6bd28b2ee3cb25bf7620150617-13080-197v1bm20150617-13080-q57vxf'
Command :: PATH=/opt/imagemagick-6.9/bin:$PATH; file -b --mime '/tmp/2251fc5821941d6bd28b2ee3cb25bf7620150617-13080-197v1bm20150617-13080-q57vxf'
Command :: PATH=/opt/imagemagick-6.9/bin:$PATH; file -b --mime '/tmp/2251fc5821941d6bd28b2ee3cb25bf7620150617-13080-1o3we23.png'

我需要将小型,大型和原始图像存储到我的项目公共目录中,但它只存储原始

2 个答案:

答案 0 :(得分:0)

检查您的图像magick是否正确安装,因为调整大小取决于图像magick。

一次性刷新所有已定义的样式(:thumb,:small,:来自上例的中等)

rake paperclip:refresh CLASS=Modelname

并仅刷新缺少的样式: 将在文件“/public/system/paperclip_attachments.yml”中定义或更新样式列表

rake paperclip:refresh:missing_styles

此外,如果您只想重新处理单一样式,可以这样做:

users_to_reprocess.each do |user|
  user.image.reprocess! :small
end

答案 1 :(得分:0)

您可以在模型中使用:styles paperclip个宝石。像,

has_attached_file :photo,
  :styles => {
    :thumb=> "100x100#",
    :small  => "150x150>",
    :medium => "300x300>",
    :large =>   "400x400>" }

您的照片网址如下:/public/photos/(event#)/(size_name)/image_name

您必须安装ImageMagickrb-magick端口才能实现此目的。

有关详细信息,请参阅此链接Upload Image using Paperclip gem