回答
默認情況下,Rake任務刷新所有縮略圖。請記住,它不會觸摸/處理原始圖像。
你可以有一個look at the Rakefile和Attachment類和修改,以允許你指定一個特定的縮略圖大小,但目前的設計假設你想要原始的原始和重做所有縮略圖。
我克服了這一點 - 這不是優雅的,但它對我有效。
您的一個樣式應該具有與所有其他樣式不同的尺寸。這樣,在您的自定義回形針處理器中,您可以查看命令字符串的內容是否包含給定的尺寸。如果是這樣,你會做特殊處理,否則,你不會。
(我修剪這些代碼 - 而修改了它 - 從瑞安貝特的Railscast集182)
module Paperclip
class Cropper < Thumbnail
def transformation_command
SPECIAL_PROCESSING_FLAG = "150x150"
if crop_command && super.include?(SPECIAL_PROCESSING_FLAG)
crop_command + super.sub(/ -crop \S+/, '')
else
super 'do nothing fancy
end
end
def crop_command
target = @attachment.instance
if target.cropping?
" -crop '#{target.crop_w.to_i}x#{target.crop_h.to_i}+#{target.crop_x.to_i}+#{target.crop_y.to_i}'"
end
end
end
end
在我的情況它沒有問題,我們在非特殊情況下重新處理過,因爲最終的結果沒有改變。
我最近有一個類似的問題,並在留言板上找到了這個解決方案。希望能幫助到你!
has_attached_file :screenshot,
:default_style => :full,
:styles => {
:full => "280x210",
:cropped => { :processors => [:screenshot_crop] }
}
感謝您的提示!看來你應該提供`:geometry`參數 - `:cropped => {:geometry =>'whatever',:processors => [:screenshot_crop]}`否則它給出'undefined method \`[]'nil: NilClass`。 – jibiel 2012-04-18 09:59:13
將此代碼添加到您的paperclip.rake文件:
desc "Reprocesses your attachments style (set CLASS, ATTACHMENT and STYLE)"
task :style => :environment do
module JustForOneDay
NAME = ENV['STYLE']
end
module ::Paperclip
class Attachment
def post_process_styles #:nodoc:
@styles.each do |name, args|
if JustForOneDay::NAME == name
begin
raise RuntimeError.new("Style #{name} has no processors defined.") if args[:processors].blank?
@queued_for_write[name] = args[:processors].inject(@queued_for_write[:original]) do |file, processor|
Paperclip.processor(processor).make(file, args, self)
end
rescue PaperclipError => e
log("An error was received while processing: #{e.inspect}")
(@errors[:processing] ||= []) << e.message if @whiny
end
end
end
end
end
end
for_all_attachments do |instance, name|
result = instance.send(name).reprocess!
end
end
end
用回形針測試2.3.1.1
在回形針2.3.3這應該是:
def post_process_styles #:nodoc:
styles.each do |name, style|
if JustForOneDay::NAME == name
begin
raise RuntimeError.new("Style #{name} has no processors defined.") if style.processors.blank?
@queued_for_write[name] = style.processors.inject(@queued_for_write[:original]) do |file, processor|
Paperclip.processor(processor).make(file, style.processor_options, self)
end
rescue PaperclipError => e
log("An error was received while processing: #{e.inspect}")
(@errors[:processing] ||= []) << e.message if @whiny
end
end
end
end
很簡單,只需在回形針版本中找到attachment.rb文件即可。
- 1. 回形針v2.3.8不處理風格
- 2. 回形針處理器從其他風格生成圖像
- 3. 回形針NoHandlerError定製處理器
- 4. 回形針 - 風格lambda
- 5. 回形針處理器 - 如何在我自己的處理器中使用回形針記錄器?
- 6. S3上的回形針處理器超時
- 7. 錯誤回形針/ FasterCSV處理可選csv上傳
- 8. Android上運行的處理器運行
- 9. 處理OOP風格的圖形
- 10. 處理C風格回調的綁定生成器(如SWIG)?
- 11. 在特定處理器上運行批處理文件
- 12. 回形針自定義處理器不改變圖像類型
- 13. 自定義回形針處理器未被調用
- 14. 回形針附件的後臺處理
- 15. 風格定義時,回形針不保存原始文件
- 16. Java Spring風格:針對給定類別的處理器類別的工廠
- 17. filename..extension //回形針重新處理
- 18. 僅回形針處理圖像
- 19. 後處理S3資產與回形針
- 20. 導軌回形針批處理
- 21. Rails /回形針 - 跳過圖像處理
- 22. 回形針處理器未在Rails 3.0.0rc中加載
- 23. 上傳之前的回形針處理文件內容
- 24. 回形針處理器無法找到它的文件
- 25. 回形針 - 檢查給定的格式
- 26. 只能在一個處理器上進行運行只能在其他處理器上運行線程嗎?
- 27. youtube視頻上傳與uploadify和回形針定製處理器在軌道上的紅寶石?
- 28. REST風格的後處理
- 29. 回形針在每個頁面上多次運行
- 30. 回形針不同的風格與不同的權限
是否還有其他選項僅裁剪:拇指圖像而讓其他人獨自一人?我的意思是不修改附件類? 也許模型/控制器中有一些額外的代碼? – astropanic 2009-07-23 07:07:15