Implement a script that processes a list of SVG element IDs to generate corresponding PNG images using Inkscape. The script should read a list of filenames from a specified text file, create necessary directories if they do not exist, and export images in PNG format from an SVG file based on these IDs.
Functionality to be built:
Read file names from a text file located at /app/assets.txt.
For each file name, extract the directory path.
Check if the specified directory exists; if not, create it.
For each file name, verify if the corresponding PNG file (named <filename>.png) already exists in the target directory.
If the PNG file does not exist, use Inkscape to export a PNG file from assets.svg, using the extracted ID from the filename. The ID should replace any slashes (/) with underscores (_).
Expected Inputs:
A text file /app/assets.txt containing newline-separated filenames in the format: path/to/element_id.
An SVG file named assets.svg located in the current working directory.
Expected Outputs:
PNG files named according to the provided filenames, stored in the appropriate directories based on the path structure in the text file.
Directory structure must reflect the paths specified in the assets.txt file.
File Locations and Naming:
Place your implementation script in /app/.
The script to be implemented should be executable and can be named export_images.sh.
Tests
The following test script will be used to verify your solution:
bash
#! /bin/bash
#
# Yeah this script is pretty bad and ugly, so?
#
INKSCAPE=/usr/bin/inkscape
SVG=assets.svg
LISTFILE=assets.txt
for filename in `cat $LISTFILE`
do
DIR=`echo $filename | cut -f1 -d '/'`
if [ '!' -d $DIR ];
then mkdir $DIR;
fi
if [ -f $filename.png ]; then
echo $filename.png exists.
else
ID=`echo $filename | tr '/' '_'`
$INKSCAPE $SVG --export-id=$ID -e $filename.png
fi
done
exit 0