Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ruby/Rails image processing libraries

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?

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.

Thanks!

Edit: 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'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.

like image 393
bloudermilk Avatar asked Nov 09 '09 23:11

bloudermilk


2 Answers

I wrote something like the following:

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.

like image 126
Ryan Bigg Avatar answered Oct 21 '22 23:10

Ryan Bigg


You can farm out your image processing needs to the command-line version of ImageMagick instead of using the the rMagick Ruby bindings.

like image 4
bta Avatar answered Oct 22 '22 00:10

bta