views:

55

answers:

2

Before I start rolling my own using Rmagick I though i'd ask as this is probably a quite common use case. I have a few hundred email addresses which I would like to display to the user for each entry however I would like to avoid displaying the emails as plain text to avoid scraping, so I'm looking for some text-to-image solution.

It be quite simple but of course I only want to generate the image once per entry and then store the image somewhere, i'm currently using paperclip with s3 as I'm hosting on Heroku, etc.

Another possibility is to require the user to fill out a captcha in order to obtain the email, but that seems a bit overkill.

Any suggestions?

Thanks

A: 

Might be worth looking into libgd2 (the gd2 gem) which is lighter weight than rmagick and ImageMagick. Not sure if they've implemented text functions in the gem, but it's not difficult to extend to call other libgd2 functions.

fullware
+1  A: 

A basic rmagick solution isn't that bad, 6 lines. The following gives you a yellow rectangle with TEXT in the center. You can experiment with the font and point size. The center call is there because I thought it looked better in the middle.

require 'RMagick'

canvas = Magick::Image.new(300, 100){self.background_color = 'yellow'}
gc = Magick::Draw.new
gc.pointsize(50)
gc.text(30,70, "TEXT".center(14))

gc.draw(canvas)
canvas.write('tst.png')
Paul Rubel