当前位置:首页 > 开发 > 编程语言 > 编程 > 正文

paperclip一些使用技巧

发表于: 2012-07-29   作者:hotsunshine   来源:转载   浏览:
摘要: 一、关于styles设置,缩略图的切割策略 有两个符号,一个是‘#’,另一个是‘>’,说明如下: 引用 trailing #, thumbnail will be centrally cropped, ensuring the requested dimensions. trailing >, thumbnail will only be modified if it i
一、关于styles设置,缩略图的切割策略
有两个符号,一个是‘#’,另一个是‘>’,说明如下:
引用
trailing #, thumbnail will be centrally cropped, ensuring the requested dimensions.
trailing >, thumbnail will only be modified if it is currently larger requested dimensions. (i.e. the :small thumb for a 120×80 original image will be unchanged)

还有其他的符号:
http://www.imagemagick.org/Usage/resize/

另外如果仅仅写“120x”生成的图片会缩略成120像素宽的图,高度进行自动调整
如果写"x80"生成的图片会缩略成80像素高的图,宽度自动调整

二、批量处理图片的task任务
引用
You can (re)generate your thumbnails en masse with Paperclip’s rake tasks. Using our example class above:

rake paperclip:refresh:thumbnails CLASS=User


or to refresh all of your defined styles in one go (:thumb, :small, :medium from the above example)

rake paperclip:refresh CLASS=User


and to refresh only missing styles:
a list of styles will be defined or updated in a file “/public/system/paperclip_attachments.yml”

rake paperclip:refresh:missing_styles


If you are using the gem required version of paperclip the rake tasks may not be auto-loaded, but you can copy them into your lib/tasks directory if needed.

If you need more manual control or have a lot of thumbnails and only want to process a few, you can use #reprocess! like so:

users_to_reprocess.each do |user|
  user.photo.reprocess!
end


paperclip一些使用技巧

  • 0

    开心

    开心

  • 0

    板砖

    板砖

  • 0

    感动

    感动

  • 0

    有用

    有用

  • 0

    疑问

    疑问

  • 0

    难过

    难过

  • 0

    无聊

    无聊

  • 0

    震惊

    震惊

版权所有 IT知识库 CopyRight © 2009-2015 IT知识库 IT610.com , All Rights Reserved. 京ICP备09083238号