Rmagick SVG conversion different than ImageMagick - ruby-on-rails

Here's a link to my test: http://pestnow.herokuapp.com/tester/svg The image on the left is SVG, the one on the right is the PNG conversion. Here's the extremely simple code for the conversion:
def self.svg_to_png(svg)
img = Magick::Image::from_blob(svg)
return img[0].to_blob {self.format = 'PNG'}
end
I've been struggling with this problem and had this answered question here: SVG to PNG Conversion with ImageMagick doesn't handle defs? That question had to do with getting IM to do the conversion properly. And it DOES, from the command line with a simple "convert test.svg test.png"
But the RMagick conversion doesn't work the same. On my local dev box, I do have ImageMagick compiled with RVG support, and that fixed the command line. But I have no clue how to make RMagick use it the same way.
Furthermore, I'm hoping its something I need to do in my code, and not some feature required on the server, because this app is hosted on heroku and I have no control over how they install IM.

I should have reported back.
Yes, Heroku has IM, but they don't support it. It's just there as part of the long term support version of (I believe) Ubuntu that they use. We talked back and forth a few times, and they have said that they might upgrade it in the future, along with other linux libs / utils, but that there was no definite timeframe. My guess is, maybe on the next stack.
Until then, I've stopped using symbols in my SVG and had to do a few tricks on order of transforms, but for the most part I have things working. Another piece of advice is to make sure you are using the EXACT version of IM that Heroku uses on your Dev box. Saves a lot of heartache.

Related

Font rendering issues with wkhtmltoimage

I have a Rails app which uses wkhtmltoimage to render an image. The font used in the image is Lucida Grande, included via inline data-uris. On my local Mac everything works just fine, but on the remote server (Ubuntu 12.10) the font just looks weird. Both are using wkhtmltoimage 0.10.0 rc2.
The left one is generated on my Mac, the right one on the Ubuntu server.
Any ideas whats going on?
Unfortunately I haven't found a solution for this problem. But today I was lucky enough to find a workaround! :)
After reading Thomas Fuchs' Embedding Canvas and SVG charts in emails I went the radical way and completely replaced wkhtmltoimage with PhantomJS. I also used his gist to install some dependencies. And here are the results:
wkhtmltoimage local & remote:
PhantomJS local & remote:
Though there are still small differences, PhantomJS does its job quite good! So I will use this for now, and close this question :)

Ruby on Rails command line looks weird

I just began learning RoR using the materials from railstutorial.org. When the author uses the command line, the resulting text are always nicely organized and colored. When I do the same thing, I often get "weird" characters and unorganized text as result.
http://i.imgur.com/2Q0kzwf.jpg
Example
http://i.imgur.com/mZP4SI9.jpg
My attempt to do the same
I'm not quite sure what to do to make my command line more organized like the one shown in the tutorial. Any help would be appreciated. In case you need to know, I'm using Windows 7.
It is because by default Windows command prompt doesn't know about ANSI color Sequences. You can try https://github.com/adoxa/ansicon which is supposed to make it aware. The reason the tutorial authors look like that is they are using a *nix shell that understands the color codes (probably bash or zsh on either linux or osx if I had to guess)
As Doon pointed out, the Windows console doesn't recognize ANSI sequences. As suggested your best bet right now is to use external tools.
However, since there are some pain points using most of the external tools, Ruby 2.0 will provide support for ANSI escape codes in Ruby out-of-the-box without having to depend on external gems or tools.

Ruby: Resize Images without ImageMagick?

Is there a way to resize images in Ruby without ImageMagick.... and also without ruby-vips? Yes, I know I am being rather narrow, but can't seem to get both of them to install on my Mac, which is kinda annoying. I just wanna resize, nothing fancy... anything lightweight?
Quick search on ruby gems.org leads to a few candidates:
http://rubygems.org/search?query=image+resize
Also, with regard to having trouble installing ImageMagick on your Mac. Do you know about Homebrew?
There used to be ImageScience, but I'm getting a lot of broken links for it when googling now.
Might also try to find Ruby lib for GD or GD2.

Rails 3 compatible image uploading with no dependencies?

OK so I'm looking for a good image uploading gem that is Rails 3 compatible and has no dependencies. I was using attachment_fu, but it's Rails 3 compatibility seems to be in question. And I really wanted to use Paperclip, but it has an image majick dependency. I'm having a hard time finding other alternatives...
Stupid question #1: Shouldnt Rails have some "official" image uploading scheme thats baked into the framework? Every web app will need it at some point, and hunting around every time for some questionable third-party way of doing this gets old after awhile.
Stupid question #2: Why can't Paperclip have a no-dependency mode that doesnt make thumbnails or resize, and just stores images as they are uploaded?
As someone who has Rails with Paperclip running on both Linux, Mac and Windows, I can tell you: installing ImageMagic (or whatever spelling is) is not a problem.
In fact, my old linux hosting already had it, Mac laptop, IIRC, too. I expected some problems installing it on windows, but had to just download installer and specify correct path in rails. No problem whatsoever.
So, in your place, I would really give it a try.
edit
There's also a number of file upload plugins for Rails, but I didn't use them and can't really give advice there. Google will give you examples.

Rails plugin Attachment_fu on Windows

I'm having problem with Rails plugin attachment_fu. On every upload, I get validation error
Size is not included in the list
I'm currently using
Rails 2.3.3
Ruby 1.8.6
The only thing I found about this problem is quite outdated discussion, which didn't help much.
Is there any solution to this problem?
I'm using attachment_fu, because I wanted to do AJAX file upload by this tutorial, but I couldn't get past the upload problem.
edit: I find only one solution that works, which is something like
def create
#image = Image.new(params[:image])
sleep 2 # for windows to catch up
#image.save ...
but I don't really like doing it this way
I think what you're really doing there is giving it time for the image processor (Rmagick or ImageScience or whatever you have hooked up) to work.
If you are are creating lots of different sizes at upload, reducing those might help.
Also, in my own experience everything runs much slower in my dev environment than it does in actual production, you may not need the hard coded delay in production.

Resources