From a Ruby app, I need to dynamically create an image file in memory. I'd prefer PNG files so I looked at chunky_png first. It'd allow me to manipulate PNG images and do a little drawing on the canvas. It does not allow me to render text as pixels, though.
What's the best way to do that?
Any hint is greatly appreciated.
You can use RMagick (doc). Note that it may be difficult to install because it requires ImageMagick libraries (unlike chunky_png which is pure Ruby).
Once installed, you may use the annotate method or the vector drawing module RVG (with the text method used in the tutorial).
Related
I'm trying to take TrueType fonts and convert them to bitmap/PNG fonts for a game. I use Ruby for most of my asset processing.
Is this possible?
I believe you will want to use canvas for that. CreateJS library will help you a lot with this. It has a built-in function for that:
http://createjs.com/docs/easeljs/classes/BitmapText.html
Ruby Bitmap Fonts is a BDF (Glyph Bitmap Distribution Format) renderer for Ruby, and able to generate a bitmap for fonts specified in BDF. It's available as a Ruby Gem too. Other libraries or tools will be able to convert font specifications to BDF.
I am making a web app using Rails 3 to make some drawing, but I need to make EPS files.
Do you know some gem or api to create EPS (Encapsulated PostScript) images?
I am not close to use another image format, maybe SVG (Scalable Vector Graphics) could be an alternative, but my requirement was using EPS's.
Thank you!
Don't know how complicated your drawings are. I could well imagine you can just do it with erb, and some helper methods. See example files at http://people.sc.fsu.edu/~jburkardt/data/eps/eps.html (open eps files in text editor)
I want to know how to open and manipulate a simple image file in Ruby language.
I don't need to do any advanced stuff, just things like open(), get_pixel() and put_pixel() and I don't wanna use any gem for doing that, but just to know the barehands-ruby way.
If by "simple image file" you refer to JPEG, GIF or so, it's tough luck because you'd have to implement all the decoding logic, which is far from being simple (take a look here for more info, but briefly because you really don't want to go into details ;)).
After decoding, eventually what you get is a matrix (two-dimensional array) of pixel information (usually three numbers for red, green and blue component, but other options exist). Then your methods get_pixel and set_pixel are trivial.
What Ruby folks usually do in such cases is wrap already existing C library for image manipulation, into a library such as rmagick.
Paperclip + ImageMagick did the trick. It's awesome and easy
We have some code that draws things using RVG in RMagick. We scale them at various sizes. What I'm trying to do is use a file that's saved as an SVG as a template.
The problem is, is when I load an SVG using Magick::Image.read, and then 'use' it, it rasterizes it, and then scales it, instead of producing pretty vectors.
Is there a way one might go about doing this properly?
Thanks!
Thoughts:
Imagemagick is fundamentally raster oriented. If you want to keep your image in vector format, don't use Imagemagick, as the author will tell you. That said, even though imagemagick may by default convert your image to raster, you can convert it back from raster into vector format (sometimes).
SVuGy may help. It doesn't appear to have a lot of support, but may work. I haven't used it.
The rmagick developer claims to have a SVG to RVG parser, you might try contacting him at rmagick AT rubyforge DOT org.
If all else fails, punt. You could write an xslt to convert your svg to rvg. The two formats are close enough that this might not be too painful. Else a tool like genshi might be a faster conversion path for you if you know more python than xlst.
I was wondering if anyone could suggest to me potential libraries in ruby for manipulating jpegs? Specifically I want to make the image 50% transparent so it can act as an overlay. The image in question would be of a house and I'd like it to overlay a village image.
Just being specific about the image as the transforms may not like multiple colours :)
Take a look at RMagick. This tutorial features transparency/opacity.
Best wishes,
Fabian
Check out RMagick