Ошибка скрепки при обработке эскиза - PullRequest
1 голос
/ 22 августа 2011

У меня ошибка при использовании Скрепка с Jcrop Я следую за наложением рельсов , чтобы сделать это. Когда я загружаю изображение, оно работает, но когда я пытаюсь обрезать его, я получаю это в моей консоли:

[paperclip] An error was received while processing: #<Paperclip::PaperclipError: There was an error processing the thumbnail for paperclip-reprocess20110822-2281-19969sz>
[paperclip] An error was received while processing: #<Paperclip::PaperclipError: There was an error processing the thumbnail for paperclip-reprocess20110822-2281-19969sz>

Вот моя модель:

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

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

    def avatar_geometry(style = :original)  
        @geometry ||= {}  
        @geometry[style] ||= Paperclip::Geometry.from_file(avatar.path(style))  
    end  

private  
    def reprocess_avatar  
        avatar.reprocess!  
    end  
end

И мой процессор:

module Paperclip  
    class Cropper < Thumbnail  
        def transformation_command  
            if crop_command  
                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  

Есть идеи, чтобы решить это? (Я на OS 10.7)

1 Ответ

2 голосов
/ 22 августа 2011

Решение найти внутри комментариев Railscast

В модели

#has_attached_file :avatar, :styles  => { :small => ["100x100#", :jpg], :large => ["500x500>",:jpg] }, :processors => [:cropper] 
has_attached_file :avatar, :styles  => { 
    :small => {:geometry => "100x100#", :processors => [:cropper]}, 
    :large => {:geometry => "500x500>"} 
}

В процессоре

#crop_command + super.sub(/ -crop \S+/, '')
crop_command + super.join(' ').sub(/ -crop \S+/, '').split(' ')
...