tario / imageruby

flexible and easy to use ruby gem for image processing
http://tario.github.com/imageruby/doc/
GNU General Public License v3.0
16 stars 1 forks source link

text to image and image compositing? #2

Open mroth opened 12 years ago

mroth commented 12 years ago

This project is very exciting to me, as I maintain a popular gem called lolcommits which I would love to move off using RMagick/ImageMagick, as the vast majority of the installation problems people have come from trying to get IM installed and working, so a pure Ruby/gem solution would be ideal.

Are there any plans on the roadmap to add image compositing or font to image capabilities to imageruby?

( had been tracking this on my side at https://github.com/mroth/lolcommits/issues/24 )

tario commented 12 years ago

Yes,

The feature of compositing you are talking about, can be achieved by using the alpha channel? (example: https://github.com/tario/imageruby/blob/master/examples/alpha.rb). Can you give me more details about you are meaning by "compositing" ?

Regarding the font to image and other aspects, image processing features in pure ruby are really difficult to implement without serious performance penalties (comparing to well known commercial and open source applications like photoshop, or gimp), because of that I had implemented two optional extensions: https://github.com/tario/imageruby-c https://github.com/tario/imageruby-bmp-c

If you want to know what I am talking about, you can benchmark (can use the examples of the gem) using them and using them not to apreciate an important difference

Of course, you can use only imageruby and imageruby-bmp, both implemented in pure ruby, but the performenace will be limited by the possibilities of the ruby implementation (I suggest using ruby 1.9)

A little more info: http://tario-project.blogspot.com.ar/2011/04/released-imageruby-flexible-ruby-image.html

mroth commented 12 years ago

Yes, I think using imageruby-c would be acceptable to keep performance high.

Yes, alpha channels would be needed, I am currently creating destination images such as this: sample

Where I am primarily doing the following actions:

  1. resizing a source JPEG from a webcam capture to 640x480 (if it's larger to begin with)
  2. creating an image of the text strings using a specific TTF font file, string, size, color and stroke parameters
  3. overlaying the image-text over the source image (with transparency), and flattening to a single jpeg
tario commented 12 years ago

Good, as example, in order to do that using the current implementation of imageruby, you need to install imageruby-devil to allow read and save on many image formats (including jpg), for the moment imageruby does not offer any specific feature to generate text with images (you should search another way to do that), Given the image with the text (image2), and the base image (image1) you should:


image2 = Image.from_file("input2.bmp")
image1 = Image.from_file("input1.jpeg")

# replace green with transparent pixel
transparent_image = image2.color_replace(Color.green, Color.from_rgba(0,0,0,0) )

# draw transparent image over image1 and save it
image1.draw(0,0, transparent_image).save("output.jpeg", :jpeg)