svg2png

svg2png is a perl script to convert the svg files in the current directory into png images, doing the conversion only if the svg file is newer than its corresponding png.

Usage

Simply run ./svg2png in the working directory.

On 6 January (2024), I had to amend this 2008 script with the line

    print MyMakefile "\tinkscape -h 7200 -b white -o $file.png $file \n\n";

since the export option is not -e anymore but -o. I also added the -b=white option to force white background. This makes version svg2png v°0.2.

Versions:

  1. v0°1: 3 November (2008).
  2. v0°2: Template:Subs:today ― last version, not the one listed below!
#! /usr/bin/perl
# svg2png v0°1   ____
# _____   ____ _|___ \ _ __  _ __   __ _ 
#/ __\ \ / / _` | __) | '_ \| '_ \ / _` |
#\__ \\ V / (_| |/ __/| |_) | | | | (_| |
#|___/ \_/ \__, |_____| .__/|_| |_|\__, |
#          |___/      |_|          |___/ 
#
# F.P. Laussy - Mon Nov  3 15:05:54 GMT 2008
# F.P.Laussy@soton.ac.uk
# Convert svg files of the current directory into high-quality png
# Do this only if timestamp of svg is newer than its png
# Bind all png together with -b option (into presentation.png)

use Getopt::Std;
getopts("b",\%options);

@files = <*.svg>;

# Build makefile
my $pngfiles = "";

open (MyMakefile, '>Makefile');

foreach $file (@files) {
    $pngfiles .= "$file.png ";
}

print MyMakefile "presentation.png : $pngfiles";

if ($options{b}){
    print MyMakefile "\n\tpdftk $pdffiles cat output presentation.pdf"
}

print MyMakefile "\n\n";

# dependencies

@files = <*.svg>;
foreach $file (@files) {
    print MyMakefile "$file.png : $file \n";
    print MyMakefile "\tinkscape -h 7200 -e $file.png $file \n\n";
}
 
close (MyMakefile);

system("make");
#system("rm Makefile");

print "svg2png has finished!\n";