2013-08-09 2 views
1

업로드 된 이미지의 너비를 100 %로 유지하면서 너비의 60 % 만 자르기 위해 Paperclip 스타일을 작성하려면 어떻게해야합니까? 이 같은종이 클립 : 너비는 100 %, 너비는 높이의 60 %입니다.

뭔가 : 아래에서 추출 차원에 문제가있는 경우

has_attached_file :image, :styles => { :cropped => "100%x[60% of height]" } 

답변

1
has_attached_file :image, :styles => { 
         :original => "100x60>", 
         :thumb => Proc.new { |instance| instance.resize } 
        } 
    #### End Paperclip #### 

    def resize  
    geo = Paperclip::Geometry.from_file(image.to_file(:original)) 
    height = (geo.width.to_i * 60)/100 
    width = geo.width  
    "#{width.round}x#{height.round}!"  
    end 

희망이 당신에게

+0

도움이 될 나는 정의되지 않은 지역 변수 또는 메소드 'image'''에 대한'NameError'를 얻을. 내가 이미지 이름에 사용하는 것으로 '이미지'를 변경하려고 시도했지만 아직 아무것도 아닙니다. 어떤 충고? –

+0

새로운 저장에, 대신 매개 변수로'main_image.queued_for_write [: original] .path'를 사용해야했습니다. – RNickMcCandless

관련 문제