Svg2png: Difference between revisions
Fabrice P. Laussy's Web
Fabrice (talk | contribs)
m Created page with "= svg2png = <tt>svg2png</tt> 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 th..."
 
mNo edit summary
 
(2 intermediate revisions by 2 users not shown)
Line 7: Line 7:
Simply run <tt>./svg2png</tt> in the working directory.
Simply run <tt>./svg2png</tt> in the working directory.


== Source ==
On {{thisday|6|January|2024}}, {{I}} had to amend this [[2008]] script with the line
 
<pre>
    print MyMakefile "\tinkscape -h 7200 -b white -o $file.png $file \n\n";
</pre>
 
since the export option is not <tt>-e</tt> anymore but <tt>-o</tt>. I also added the <tt>-b=white</tt> option to force white background. This makes [[:File:svg2png.gz|version svg2png v°0.2]].
 
== Versions: ==
 
# v0°1: {{thisday|3|November|2008}}.
# 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 v0°1   ____
# svg2png v0°3   ____
# _____  ____ _|___ \ _ __  _ __  __ _  
# _____  ____ _|___ \ _ __  _ __  __ _  
#/ __\ \ / / _` | __) | '_ \| '_ \ / _` |
#/ __\ \ / / _` | __) | '_ \| '_ \ / _` |
Line 18: Line 30:
#          |___/      |_|          |___/  
#          |___/      |_|          |___/  
#
#
# F.P. Laussy - Mon Nov 3 15:05:54 GMT 2008
# F.P. Laussy - Wed Feb 5 CET 2025
# F.P.Laussy@soton.ac.uk
# 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 35: Line 47:


foreach $file (@files) {
foreach $file (@files) {
     $pngfiles .= "$file.png ";
    my $pngfile = $file;
    $pngfile =~ s/\.svg//g;   
     $pngfiles .= "$pngfile.png ";
}
}


Line 50: Line 64:
@files = <*.svg>;
@files = <*.svg>;
foreach $file (@files) {
foreach $file (@files) {
     print MyMakefile "$file.png : $file \n";
    my $pngfile = $file;
     print MyMakefile "\tinkscape -h 7200 -e $file.png $file \n\n";
    $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";
}
}
   
   

Latest revision as of 10:38, 5 February 2025

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: 6 January (2024), update obsolete option, white background.
  3. v0°3: 5 February (2025), export with ".png" extension as opposed to ".svg.png".
#! /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";