2009-07-22 3 views

답변

1

기본적으로 레이크 작업은 모든 축소판을 새로 고칩니다. 원본 이미지를 만지거나 처리하지 않는다는 점에 유의하십시오.

look at the Rakefile 클래스와 Attachment 클래스를 가질 수 있으며 특정 축소판 크기를 지정할 수 있도록 수정해도되지만 현재 디자인에서는 원본을 가져 와서 원본에서 모든 축소판을 다시 실행한다고 가정합니다.

+0

다른 이미지를 잘라내는 다른 옵션이 있습니까? Attachment 클래스를 수정하지 않고 말은합니까? 모델/컨트롤러에 추가 코드가있을 수 있습니까? – astropanic

0

나는 이걸 풀 렸습니다. 우아하지는 않지만 저에게 효과적이었습니다.

하나의 스타일은 다른 모든 스타일과 다른 치수를 가져야합니다. 이런 방법으로 사용자 지정 Paperclip Processor에서 명령 문자열의 내용에 지정된 차원이 포함되어 있는지 확인할 수 있습니다. 그렇다면 특별한 처리를 할 것입니다. 그렇지 않다면 그렇게하지 않을 것입니다. 내 상황에서

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 

우리가 너무 비 특별한 경우에 재 처리하는 것이 중요하지 않았다

은 (라이언 노여움의 Railscast 에피소드 (182)에서이 코드를 클립 - - 그리고 그것을 수정) 최종 결과가 아무 것도 변경하지 않았기 때문입니다.

18

나는 최근에 비슷한 문제가있어서 메시지 보드에이 해결책을 발견했습니다. 희망이 도움이됩니다!

has_attached_file :screenshot, 
:default_style => :full, 
:styles => { 
    :full => "280x210", 
    :cropped => { :processors => [:screenshot_crop] } 
} 
+0

팁 주셔서 감사! 어쨌든': geometry => {: geometry => 'whatever', : processors => [: screenshot_crop]}'': geometry '매개 변수를 제공해야합니다. 그렇지 않으면 nil에''undefined method \'[]' NilClass'. – jibiel

1

당신의 paperclip.rake 파일에이 코드를 추가

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 

:

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에서이 있어야한다 종이 클립과 테스트 간단합니다. 클립 클립의 attachment.rb 파일로 이동하십시오.