Rails 的简单文本到图像解决方案

发布于 2024-09-11 06:00:01 字数 275 浏览 11 评论 0原文

在我开始使用 Rmagick 自己开发之前,我想问一下,因为这可能是一个非常常见的用例。我有几百个电子邮件地址,我想为每个条目向用户显示这些地址,但是我想避免将电子邮件显示为纯文本以避免抓取,所以我正在寻找一些文本到图像的解决方案。

这很简单,但当然我只想为每个条目生成一次图像,然后将图像存储在某个地方,我目前正在使用带有 s3 的回形针,因为我在 Heroku 上托管等。

另一种可能性是要求用户填写验证码才能获取电子邮件,但这似乎有点矫枉过正。

有什么建议吗?

谢谢

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

舞袖。长 2024-09-18 06:00:01

基本的 rmagick 解决方案还不错,只有 6 行。下面给出了一个黄色矩形,中间有 TEXT。您可以尝试字体和磅值。中心呼叫在那里是因为我认为它在中间看起来更好。

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')

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')
月依秋水 2024-09-18 06:00:01

可能值得研究一下 libgd2(gd2 gem),它比 rmagick 和 ImageMagick 更轻。不确定他们是否在 gem 中实现了文本函数,但是扩展调用其他 libgd2 函数并不困难。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文