Ruby/Rails image processing libraries

后端 未结 6 2182
深忆病人
深忆病人 2020-12-28 18:35

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 banne

相关标签:
6条回答
  • 2020-12-28 19:19

    The ImageScience library is made for people who hate rMagick's poor memory usage, etc. I use it as a backend processor for the attachment_fu plugin, which makes it easy to make an image model in Rails.

    0 讨论(0)
  • 2020-12-28 19:20

    You can use mini-magick to work with ImageMagick in Ruby.

    0 讨论(0)
  • 2020-12-28 19:25

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

    0 讨论(0)
  • 2020-12-28 19:30

    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.

    0 讨论(0)
  • 2020-12-28 19:32

    Recently I have been experimenting with creating charts/graphs from data sets using Ruby. When I was unable to find any libraries or gems that really did what I wanted, I started tinkering around with SVG graphics and I found that they are actually fairly simple to create. The SVG format is simply plain-text XML. I built an SVG image in Inkscape, saved it to a plain SVG file, and my Ruby script uses that file as a template (I dynamically update a few line elements and several text labels and leave the structure of the file intact). SVG gives you all sorts of font options (like CSS or HTML).

    These two tutorials give you a quick look at SVG and how you can build an image fairly quickly with any app or language that can write to a text file. Ruby can use plain old puts to build a SVG file, or you can let the 'builder' gem do the formatting for you.

    0 讨论(0)
  • 2020-12-28 19:38

    Are you limited to MRI Ruby? If there's any way you can get access to a jRuby instance (maybe on an EC2 stack for instance) you could make use of the wonderful Processing library. A project I worked on before did something similar with Processing via jRuby, it's really quite a potent combination.

    0 讨论(0)
提交回复
热议问题