Update of my 2008 script! |
|||
| Line 18: | Line 18: | ||
# v0°1: {{thisday|3|November|2008}}. | # v0°1: {{thisday|3|November|2008}}. | ||
# | # [[:File:svg2png.gz|v0°2]]: {{thisday|6|January|2024}}, update obsolete option, white background. | ||
# [[:File:svg2png.gz|v0°3]]: {{thisday|5|February|2025}}, export with ".png" extension as opposed to ".svg.png". | |||
<pre> | <pre> | ||
#! /usr/bin/perl | #! /usr/bin/perl | ||
# svg2png | # svg2png v0°3 ____ | ||
# _____ ____ _|___ \ _ __ _ __ __ _ | # _____ ____ _|___ \ _ __ _ __ __ _ | ||
#/ __\ \ / / _` | __) | '_ \| '_ \ / _` | | #/ __\ \ / / _` | __) | '_ \| '_ \ / _` | | ||
| Line 29: | Line 30: | ||
# |___/ |_| |___/ | # |___/ |_| |___/ | ||
# | # | ||
# F.P. Laussy - | # F.P. Laussy - Wed Feb 5 CET 2025 | ||
# | # fabrice.laussy@gmail.com | ||
# Convert svg files of the current directory into high-quality png | # Convert svg files of the current directory into high-quality png | ||
# Do this only if timestamp of svg is newer than its png | # Do this only if timestamp of svg is newer than its png | ||
| Line 46: | Line 47: | ||
foreach $file (@files) { | foreach $file (@files) { | ||
$pngfiles .= "$ | my $pngfile = $file; | ||
$pngfile =~ s/\.svg//g; | |||
$pngfiles .= "$pngfile.png "; | |||
} | } | ||
| Line 61: | Line 64: | ||
@files = <*.svg>; | @files = <*.svg>; | ||
foreach $file (@files) { | foreach $file (@files) { | ||
print MyMakefile "$ | my $pngfile = $file; | ||
print MyMakefile "\tinkscape -h 7200 - | $pngfile =~ s/\.svg//g; | ||
print MyMakefile "$pngfile.png : $pngfile.svg \n"; | |||
print MyMakefile "\tinkscape -h 7200 -b white -o $pngfile.png $pngfile.svg \n\n"; | |||
} | } | ||
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.
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.
#! /usr/bin/perl
# svg2png v0°3 ____
# _____ ____ _|___ \ _ __ _ __ __ _
#/ __\ \ / / _` | __) | '_ \| '_ \ / _` |
#\__ \\ V / (_| |/ __/| |_) | | | | (_| |
#|___/ \_/ \__, |_____| .__/|_| |_|\__, |
# |___/ |_| |___/
#
# F.P. Laussy - Wed Feb 5 CET 2025
# fabrice.laussy@gmail.com
# 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) {
my $pngfile = $file;
$pngfile =~ s/\.svg//g;
$pngfiles .= "$pngfile.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) {
my $pngfile = $file;
$pngfile =~ s/\.svg//g;
print MyMakefile "$pngfile.png : $pngfile.svg \n";
print MyMakefile "\tinkscape -h 7200 -b white -o $pngfile.png $pngfile.svg \n\n";
}
close (MyMakefile);
system("make");
#system("rm Makefile");
print "svg2png has finished!\n";