#!/bin/bash
#
# last edited: Monday, 05/10/2021

curdir=$PWD

if [ ! -x "/usr/bin/inkscape" ]; then 
	DIALOG=Xdialog
	$DIALOG   --rc-file /usr/share/pixmaps/colorboxDOH.rc  --icon /usr/share/pixmaps/doh.xpm  --title "DOH!" \
		--msgbox "\nInkscape needs to be installed\n\nVisit absolutelinux.org to download the package!\n" 0 0
	exit 0
fi

pth=`dirname "$1"`
cd $pth
_path=`echo $1 | tr ' ' '_'` 2>/dev/null
mv "$1" `echo $1 | tr ' ' '_'` 2>/dev/null


	new1=`echo "$_path" | sed 's/\.svg/\_T.png/'`
	newname=`echo "$_path" | sed 's/\.svg/\.png/'`
	jname=`echo "$_path" | sed 's/\.svg/\.jpg/'`
	xlname=`echo "$_path" | sed 's/\.svg/\.jxl/'`
	avname=`echo "$_path" | sed 's/\.svg/\.avif/'`
	wname=`echo "$_path" | sed 's/\.svg/\.webp/'`
	inkscape --export-png=$new1 --export-background-opacity=0 --without-gui $_path
	inkscape --export-png=$newname --export-background=white --export-background-opacity=1 --without-gui $_path
	convert -quality 92 $newname $jname
	cjxl "$new1" "$xlname" -q 85
	avifenc --min 30 --max 30 "$new1" "$avname" 
	cwebp -q 90 $new1 -o $wname	

echo "Done."

