Ruby / Rails图像处理库 [英] Ruby/Rails image processing libraries

查看:155
本文介绍了Ruby / Rails图像处理库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

stackoverflow的好朋友,我今天在这里是关于在Rails环境中使用Ruby进行图像处理/操作的指导。我正在制作即时动态横幅广告,这些广告主要包含(如果不是完整的)文字。这只是一两行的相当简单,但我想选择调整字体,文字颜色,文字大小等。

Good friends of stackoverflow, I am here today for guidance regarding image processing/manipulation using Ruby in a Rails environment. I'm creating on-the-fly dynamic banner ads that will feature mostly (if not completely) text. It's fairly simple with just a line or two, but I'd like the option to adjust font, text color, text size, etc.

你推荐哪些图书馆?这样的任务?

What libraries do you recommend for this sort of task?

我已经在rMagick中读了一些内容,我看到很多关于内存问题和缺乏文本呈现功能的抱怨。我没有看到很多其他活跃项目。

I've read up in rMagick a little bit and I see a lot of complaints about memory issues and lack of text rendering features. I'm not seeing many alternative active projects.

谢谢!

编辑:我有机会搞乱RMagick,虽然它的库是全功能的,但它在文本部门严重缺乏。我无法使用的一个功能是不间断的空间。我在我的文本中打印了一个电话号码,区号与其他号码不同,这是没有意义的。

I got a chance to mess around with RMagick and while it's library is full featured, it seriously lacks in the text department. One feature I'm unable to use is non-breaking spaces. I'm printing a phone number in my text and it really doesn't make sense to have the area code on a different line than the rest of the number.

I选择RMagick是目前最好的解决方案,因为它功能齐全且积极开发,但绝不是良好的解决方案。

I'm choosing RMagick as the best solution for now, because it's full-featured and actively developed, but it is by no means a good solution.

推荐答案

我写了如下内容:

require 'rubygems'
require 'RMagick'
include Magick

image = Image.new(50, 50) {
  self.background_color = "white"
}
text = Draw.new
text.annotate(image, 0,0,0,40, 'Named Colors') {
     self.fill = 'black'
     self.pointsize = 32
}
image.write("image.png")

哪个应该是很容易遵循。另请参阅文档。虽然它并不完美,但它几乎都在那里。

Which should be easy enough to follow. Also have a look at the documentation. Whilst it's not quite laid out to perfection, it's pretty much all there.

这篇关于Ruby / Rails图像处理库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆