Friday, 15 January 2010

ruby on rails - How to add text to image? -



ruby on rails - How to add text to image? -

i trying add together text on image rmagick. code:

version :thumb process :resize_to_limit => [400, 300] process :addt end def addt manipulate! |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

the problem code totally blocks application. can't open other part of site , can't turn off server process. need kill server process start application again.

what problem?

just seek this, cant solve code . hope 1 can help that.

1st install gem source: https://github.com/rmagick/rmagick

next start playing rmagick, can stick in 1 of controllers:

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 want add together in 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

hope 1 help you..

if cant understand ..click http://mikewilliamson.wordpress.com/2010/04/29/adding-text-to-pictures-with-rmagick-and-rails/

ruby-on-rails ruby-on-rails-4 rmagick watermark

No comments:

Post a Comment