2014-06-23 3 views
3

RMagick으로 이미지에 텍스트를 추가하려고합니다. 이것은 내 코드입니다.이미지에 텍스트를 추가하는 방법은 무엇입니까?

version :thumb do 
    process :resize_to_limit => [400, 300] 
    process :addt 
end 

def addt 
    manipulate! do |img| 
     title = Magick::Draw.new 
     img = title.annotate(img, 0,0,0,40, 'test') { 
      self.font_family = 'Helvetica' 
      self.fill = 'white' 
      self.stroke = 'transparent' 
      self.pointsize = 32 
      self.font_weight = Magick::BoldWeight 
      self.gravity = Magick::CenterGravity 
     } 

    end 
end 

이 코드의 문제점은 응용 프로그램을 완전히 차단한다는 것입니다. 내 사이트의 다른 부분을 열 수 없으며 서버 프로세스를 끌 수 없습니다. 응용 프로그램을 다시 시작하려면 서버 프로세스를 완전히 종료해야합니다.

무엇이 문제입니까?

+0

IRB 콘솔에서이 작업을 시도 했습니까? – tebayoso

답변

5

그냥 시도해보십시오. 코드를 해결할 수 없습니다. 그러나 이것으로 당신을 도울 수 있기를 바랍니다.

1이 보석을 소스 설치 :https://github.com/rmagick/rmagick

다음 가 RMagick과 재생을 시작하기 위해, 당신은 당신의 컨트롤러 중 하나이 막대기 수 있습니다

require ‘RMagick’ 
include Magick 

def addt 

img = ImageList.new(‘Your image path eg.public/computer-cat.jpg’) 
txt = Draw.new 
img.annotate(txt, 0,0,0,0, “The text you want to add in the image”){ 
txt.gravity = Magick::SouthGravity 
txt.pointsize = 25 
txt.stroke = ‘#000000′ 
txt.fill = ‘#ffffff’ 
txt.font_weight = Magick::BoldWeight 
} 

img.format = ‘jpeg’ 
send_data img.to_blob, :stream => ‘false’, :filename => ‘test.jpg’, :type => ‘image/jpeg’,  :disposition => ‘inline’ 

end 

희망이 하나의 도움을 ...

이해가되면 .. 클릭하십시오 this http://mikewilliamson.wordpress.com/2010/04/29/adding-text-to-pictures-with-rmagick-and-rails/

관련 문제