automated fast svg to raster-image (e.g. png) conversion - shell

I'm looking for a tool to convert an svg to a raster-image (png for instance) from a shell script (bash).
Currently I use inkscape --export-png=image.png --export-area-drawing image.svg which works well, but is terribly slow.
Searching the Web and SO only gets me libraries to do this inside some programming language (php, js, C#, ...). I could write myself a small program to do this, but I would prefer an existing tool (other than inkscape as it is quite slow).

It is possible using librsvg2
All the details are here

The ImageMagick library also has command-line tools that can do this. While it certainly supports SVG I'm not sure if it will give the same quality of results as InkScape unless your svg's are fairly simple..

I you want to batch export whole or parts of SVG files to PNG in different sizes take a look at my tool inkmake.

Related

markdown or markup to powerpoint?

I need to maintain some slides in both latex beamer and in powerpoint. (This is to make slides available for instructors elsewhere, too, 90% of which do not know how to use latex and are unwilling to learn it. and I am a latex guy on linux.)
I have tried the route via Libreoffice (and opendocument), but this did not come out well. right now, the best method that I have found is to author pdf in beamer, then run it through a nuance OCR program to get MS Word...and not even go all the way to Powerpoint (which is where I really need to be).
If I only had a markup language that produced nice Powerpoint, I could probably code a perl translator from markdown to this intermediate markup language. (going from markdown to latex beamer is relatively easy.)
I don't think this exists, but hope springs eternal. after all, it is almost 2014 now. does anyone know of a solution?
One solution is to use odpdown: It converts markdown to the OpenOffice Presenter format, which can be imported into PowerPoint.
It is not yet complete, i.e. table support is missing and possibly not running on certain Windows setups, but nevertheless it could be a start. Possibly, you have Linux running, where it seems to work.
Steve Rindsberg's answer in the comments works on PP 2007 works! Let me repeat it here:
I suspect that PowerPoint is the likeliest solution. ;-) But what sort
of slides are you creating? If they're simple heading and bullet point
slides, all you need to produce is a simple text file. Any text that
starts in the left column will be the heading of a new slide. Indent
one tab and it becomes a first-level bullet point under the current
heading; indent two tabs, it becomes a second level bullet point and
so on. Simply use File | Open on the text file to pull it into PPT.
Steve: Is this all that PP converts? Or is there a reference of other "sneaky" markup that PP knows about?
(pandoc: unfortunately, the conversion from libreoffice to powerpoint is pretty poor when I tried it last. I also tried to save and understand the powerpoint xml format, but that was REAL bad.)
The easiest way to handle this is to work with:
RStudio (and R if not already installed)
RMarkdown
Pandoc 2.0.5 (minimum)
Install those 3 (or 4) items, then read: https://bookdown.org/yihui/rmarkdown/powerpoint-presentation.html
The installation time is worth the time saved copy-pasting everything from scratch.
I also am a Linux guy and I also use LateX engines to create nice documents. Based on my experience, here's what you should do :
Stop writing directly in LaTeX and start using org-mode to write documents instead (I spent years writing in LaTeX and now it's over (except when I use modernv package))
Org supports latex math formulas and .org files are easily exported in .tex files
Org can also be easily exported in markdown
Once you have your markdown, there are several tools that will allow you to create a PowerPoint. Two of them are pandoc and md2pptx

How can you embed multiple SVG images in a print layout using a scripted procedure?

I currently have a script that produces a large amount of 3.5-inch-square SVG images. What I need is to be able to put these SVGs in a layout which can be easily and accurately printed.
I have tried using an HTML template, but HTML/CSS does not have sufficiently robust printing support.
What document layout language is most appropriate for handling SVG images, and how could this be implemented in a scripting language?
I use Ruby to generate my SVGs, and although preferable, it is not required that Ruby also be the language used to generate the print layout.
I'd suggest compiling all SVGs to a larger SVG, placing everything where you want it, and convert that to PDF using one of multiple options:
Using Inkscape on the command line, like
inkscape -f in.svg -A out.pdf
Using Batik
java -jar batik-rasterizer.jar -m application/pdf -d out.pdf in.svg
Using librsvg, like
rsvg-convert -f pdf -o out.pdf in.svg
(Probably the most lightweight option)
You might also be able to use the rsvg2 Ruby gem with a Cairo PDF surface. Documentation seems scarce or scattered, though.
If you have a budget, Prince is what you want. Since you've already tried to use CSS+HTML to get it working, you may have a working solution almost ready. Just generate the HTML, SVG, and CSS (use the CSS3 paged media extensions for best control), then pass it off to Prince to generate the PDF. I've used this for several projects, and it works great.
There are free options that work like Prince, notably wkhtmltopdf, but they might not respect your paging options as much as Prince.
Otherwise, you might be able to hack something together using Cairo, by creating a page-sized SVG image and laying it out, adding links to the multiple external SVG files.
Either of these options will end up generating a PDF, which is the only way to ensure that it will print the same no matter which browser or OS is being used.

Importing SVG into an RMagick RVG session

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.

What is the difference between ImageMagick and libGD?

I don't know anything about either library but I have to choose one of them.
Which one whould you recommend?
I'm using Perl. I need to generate images for weather site. The image is generated for a location and should contain temperature and a weather condition image inside. I guess this is a piece of cake for both libs. But I want to know which one is more powerful. I've read that libGD is not able to rotate text. Maybe there are some other drawbacks? Which one generates images faster? Whose API is easier to use?
according to this source, you should use GD:
GD and other modules built on top of that (like GD::Graph) are more aimed at producing "new" images like charts.
And you can read "Develop your own weather maps and alerts with Perl and GD", which is what you're looking for.
If you some some time. try them both, play a little, and decide.
I find both to be straightforward to use ImageMagick gives you a lot more power than gd. Here are two Magick examples from my posts:
How can I use IO::Scalar with Image::Magick::Read()
How can I resize an image to fit area with Image::Magick?
to give you examples of the API.
I have used GD to create a visualization.
See Script : giss-timeline-graphs.pl on that page.
imagemagick is more robust, however libGD should be able to cover most of the image generation tasks as well. you should see perl API/functions to both of these libraries to see what is more convenient for you.

Creating nice pdfs with ruby

I would like to create pdfs with ruby. One special need is embedding a picture into text (or a textblock), which means I need to be able to let the text flow around the image. E.g. the image should be in the rigth upper corner and the text should start left of the image and continue after the image by using the whole width of the page. How can I do this in ruby? Thank you for any suggestions!
In the past to get print quality PDFs in Ruby, I used rtex.
It's fast too, which is a real bonus.
Prawn to the rescue?
I like the html -> pdf approach. Although it is probably not the best option (prawn is) it makes it easy to design the pdf. See this website. You could also go for the approach documented at jimneath.org.
Good luck
iText is the heavyweight that will allow you to do anything you want with PDFs you can bridge to it with jRuby.
Another option I used was driving open office (it has a ui less option which you can automate from Ruby)
How about having Ruby generate some LaTeX code, then use pdflatex to produce the PDF?
Although I haven't done it myself I've seen people use a headless Open Office. You can control it from Ruby and use it to generate PDF files. You can even use an Open Office template and just fill in some elements into it.

Resources