2012-09-24 2 views
2

안녕하세요 저는 클립 및 이미지 매직을 사용하여 사진을 자르려고합니다. 사진 자르기 중 일부 오류가 발생했습니다. 오류 스택은 다음과 같습니다Rails 3에서 Paperclip을 사용하여 사진 자르기 중 오류가 발생했습니다

?[32mCommand?[0m :: convert "C:/Users/Anand/AppData/Local/Temp/120120924-3568-tx 
2bxy.jpg[0]" -crop 103x103+0+0 -auto-orient "C:/Users/Anand/AppData/Local/Temp/1 
20120924-3568-tx2bxy20120924-3568-16dij9c" 
?[32mCommand?[0m :: file -b --mime "C:/Users/Anand/AppData/Local/Temp/120120924- 
3568-tx2bxy20120924-3568-16dij9c" 
[paperclip] Error while determining content type: Cocaine::CommandNotFoundError 
?[32mCommand?[0m :: identify -format %wx%h "C:/Users/Anand/AppData/Local/Temp/12 
0120924-3568-tx2bxy.jpg[0]" 
    ?[1m?[36m (0.0ms)?[0m ?[1mrollback transaction?[0m 
Completed 500 Internal Server Error in 145552ms 

NoMethodError (undefined method `exitstatus' for nil:NilClass): 
    app/models/user.rb:14:in `reprocess_photo' 
    app/models/user.rb:14:in `reprocess_photo' 
    app/models/user.rb:14:in `reprocess_photo' 
    app/models/user.rb:14:in `reprocess_photo' 
    app/models/user.rb:14:in `reprocess_photo' 
    app/models/user.rb:14:in `reprocess_photo' 
    app/models/user.rb:14:in `reprocess_photo' 
    app/controllers/users_controller.rb:67:in `block in update' 
    app/controllers/users_controller.rb:66:in `update' 


    Rendered E:/Ruby192/lib/ruby/gems/1.9.1/gems/actionpack-3.2.8/lib/action_dispa 
tch/middleware/templates/rescues/_trace.erb (10.0ms) 
    Rendered E:/Ruby192/lib/ruby/gems/1.9.1/gems/actionpack-3.2.8/lib/action_dispa 
tch/middleware/templates/rescues/_request_and_response.erb (1.0ms) 
    Rendered E:/Ruby192/lib/ruby/gems/1.9.1/gems/actionpack-3.2.8/lib/action_dispa 
tch/middleware/templates/rescues/diagnostics.erb within rescues/layout (51.0ms) 
Exiting 

모델/user.rb 파일 :.

class User < ActiveRecord::Base 
    attr_accessible :name,:photo,:crop_x,:crop_y,:crop_w,:crop_h 
    has_attached_file :photo,:styles => {:small=>"100x100#",:large=>"500x500>"},:processors => [:cropper] 
    attr_accessor :crop_x,:crop_y,:crop_w,:crop_h 
    after_update :reprocess_photo,:if=>:cropping? 

    def cropping? 
    !crop_x.blank? && !crop_y.blank? && !crop_w.blank? && !crop_h.blank? 
    end 

    private 

    def reprocess_photo 
    photo.reprocess! 
    end 

end 

내 lib 디렉토리/paperclip_processros/cropper.rb

module Paperclip 
    class Cropper < Thumbnail 
    def transformation_command 
     if crop_command 
     #this generates command : 
     #this is right #convert "C:/Users/Anand/AppData/Local/Temp/1.jpg[0]" -crop 102x102+0+0 -auto-orient "C:/Users/Anand/AppData/Local/Temp/120120924-2336-qbzroo20120924-2336-1jqbiiv.jpg" 
     crop_command + super.first.sub(/ -crop \S+/, '') 
     else 
     super 
     end 
    end 

    def crop_command 
     target = @attachment.instance 
     if target.cropping? 
     " -crop #{target.crop_w}x#{target.crop_h}+#{target.crop_x}+#{target.crop_y} " 
     end 
    end 
    end 
end 

내 설정/ENV는/dev. rb

Paperclip.options[:swallow_stderr] = false 
Paperclip.options[:command_path] = "C:/Program Files/ImageMagick-6.7.9-Q16/" 

m 사진을 업데이트하는 경우 어쩌면 반복적으로 진행됩니다. 해결책은 무엇일까요? 이미지 마법 (magick)은 당신이 내가 처음에 가졌던 같은 문제로 실행하는 확신

답변

3

를 찾을 수없는 것처럼

0

시도

Paperclip.options[:command_path] = 'C:/PROGRA~1/IMAGEM~1.0-Q' 

Paperclip.options[:command_path] = "C:/Program Files/ImageMagick-6.7.9-Q16/" 

변화가 보인다 그로 인하여 재 처리! 메서드는 after_update 콜백을 trigging하는 ActiveRecord 부모를 저장하고 있었기 때문에 reprocess_photo 메서드가 다시 호출되었습니다. 최종 결과는 컴퓨터가 할당 가능한 메모리를 다 쓸 때까지 멈추지 않는 다소 재귀적인 루프입니다.

쉬운 수정 방법은 processing이라는 부울 속성을 추가하는 것입니다.이 속성을 사용하면 이미 이미지를 다시 처리할지 여부를 결정할 수 있습니다.

attr_accessor :processing 

그런 다음 이미지가 이미 처리중인 경우 reprocess_photo를 변경하여 반환하십시오.

def reprocess_photo 
    # don't crop if the user isn't updating the photo 
    # ...or if the photo is already being processed 
    return unless (cropping? && !processing) 
    self.processing = true 
    photo.reprocess! 
    self.processing = false 
    end 
관련 문제