I've been using inkscape for a while now to add letters to comics as well as sound effects ect. I get the artwork as several image files (PNG,JPEG, whatever) so I end up importing them and saving the SVG file. which get tedious when you have to do it for 22 pages. I want to use the command line and write a bash file to automate this. I don't really see any really good examples on how the syntax of how the command line works. especially with the verbs.
What I want to do is: open a svg file that I use as a template, import the image file, Align center (horizontal and vertical) resize it to the page size (but keep the same aspect ratio. Usually I base this off the page width). save the .svg file with a new file name. then exit.
This is not straight forward, mainly because the import of png, triggers the import dialogue which requires human intervention.
I think you would need to at least start with a file created from the template which has already had the png inserted. There are various ways to do this in Linux, but would not be something achieved with the Inkscape command line.
Once you have that, then you can process the file using the Inkscape command line.
My template has to have the xlink namespace at the top, I've attached mine but for yours, just add a png, save it, then delete the png then save. That will add the xlink name space at the top of the inkscape svg
thank you for your reply. This is exactly what I was looking for. I will have to make some adjustments to the script but I now have something I can work from.
Just a few follow-up questions. Does importing this way keep the same DPI as the original file?
Hello,
I've been using inkscape for a while now to add letters to comics as well as sound effects ect. I get the artwork as several image files (PNG,JPEG, whatever) so I end up importing them and saving the SVG file. which get tedious when you have to do it for 22 pages. I want to use the command line and write a bash file to automate this. I don't really see any really good examples on how the syntax of how the command line works. especially with the verbs.
What I want to do is: open a svg file that I use as a template, import the image file, Align center (horizontal and vertical) resize it to the page size (but keep the same aspect ratio. Usually I base this off the page width). save the .svg file with a new file name. then exit.
Have you looked here already? https://inkscape.org/doc/inkscape-man.html
As far as I am aware.
This is not straight forward, mainly because the import of png, triggers the import dialogue which requires human intervention.
I think you would need to at least start with a file created from the template which has already had the png inserted. There are various ways to do this in Linux, but would not be something achieved with the Inkscape command line.
Once you have that, then you can process the file using the Inkscape command line.
after an exhaustive search i've decided to try looking at external methods of importing the image. Can you suggest a method of doing this in linux.
Can import it as embedded png, ( I didn't bother for jpeg )
For this file structure:
├── my_template.svg
├── output
├── png
├── svgAddPng.sh
└── temp
My template has to have the xlink namespace at the top, I've attached mine but for yours, just add a png, save it, then delete the png then save. That will add the xlink name space at the top of the inkscape svg
#!/bin/bash
for f in ./png/*; do
test -f $f || continue
fullname=$(basename -- "$f")
filename="${fullname%.*}"
echo $filename
base64string=$(base64 $f)
pngDimensions=$(convert $f -print "%wx%h\n" /dev/null)
echo $pngDimensions
pngX=$(echo $pngDimensions | cut -d "x" -f1)
pngY=$(echo $pngDimensions | cut -d "x" -f2)
cat ./my_template.svg >> temp/$filename.svg
sed -i '/<\/svg>/d' temp/$filename.svg
echo '<image width="'$pngX'"' 'height="'$pngY'" preserveAspectRatio="none" xlink:href="data:image/png;base64,'$base64string'" id="myPng" x="0" y="0" />' >> temp/$filename.svg
echo '</svg>' >> temp/$filename.svg
mv temp/$filename.svg output
done
It would however require a lot more work to get it usable in the way you want.
The inkscape command line can then refer to "myPng" as the id it wants to work with.
The script does assume you have 'convert' installed which is normally present with Ubuntu 20+ as part of Imagemagik
thank you for your reply. This is exactly what I was looking for. I will have to make some adjustments to the script but I now have something I can work from.
Just a few follow-up questions. Does importing this way keep the same DPI as the original file?
will this work for jpegs and tiff files as well?