Depending on configuration, this add-on requires webserver URL rewrite support!
Allows SVG (Scalable Vector Graphics) images to be stored as templates. This creates a new svg.php file in the XF root directory.
To generate a link to an SVG template (The template must have .svg at the end of the name!) ;
Code:
{{ getSvgUrl('tempate.svg') }}
Under Board information, if "Use Full Friendly URLs" (useFriendlyUrls) is set the URL generated is:
Code:
/data/svg/<style_id>/<langauge_id>/<style_last_modified>/<templateName.svg>
Otherwise
Code:
svg.php?svg=<templateName>&s=<style_id>&l=<langauge_id>&d=<style_last_modified>
Rendering SVGs to PNGs requires external support, and depending on OS this may result in odd limitations or poor rendering.
It is not recommended to use Imagick if it can be helped!
Ubuntu (using https://launchpad.net/~ondrej/+archive/ubuntu/php PPA);
Code:
sudo apt install phpX.X-imagick libmagickcore-6.q16-3-extra<br>sudo systemctl restart phpX.X-fpm
*Replace phpX.X with actual PHP version (ie: php8.1 or php8.2 or php8.3)
Note; some distro's require libmagickcore-6.q16-3-extra to be installed to enable SVG support.
Older versions of Imagick have poor SVG support, on top of Imagick's poor security reputation.
This is a generic escape hatch to plug in arbitrary png conversion, using proc_open in php.
Configure Render using proc_open option with;
Code:
<CLI-binary> {destFile} {sourceFile}
{sourceFile} is the source SVG written as a temp file {destFile} is the destination PNG file as a temp file
Alternatively input/output can be done via pipes
Note; template names are only alpha-numeric strings, which is enforced by validation before the CLI option is called
Example using resvg v0.35.0+, configure CLI - Pipe command with;
Code:
/usr/local/bin/resvg --quiet --resources-dir=/tmp/ - -c
Example using resvg, configure CLI command with;
Code:
/usr/local/bin/resvg --quiet {sourceFile} {destFile}
Pre-compiled linux x86_64 binary has been made available here. Compiled on CentOS 7, works on Ubuntu 18.04/20.04/22.04
Compiling may bind to newer versions of glibc which can cause portability issues
Code:
curl https://sh.rustup.rs -sSf | sh<br>source $HOME/.cargo/env<br>cargo install resvg<br>cp ~/.cargo/bin/resvg /usr/local/bin/resvg<br>chmod +x /usr/local/bin/resvg
Note; use snap as otherwise it is likely to have too old an instance!
Code:
sudo snap install inkscape
Configure CLI PIPE command with;
Code:
inkscape --export-type=png -p
An example of conditional CSS to use the png over the svg for mobile clients
Less:
<span>.mod_interrupt--svg.mod_interrupt</span><br><span>{</span><br> <span>&--stop</span><br> <span>{</span><br> <span>&:before</span><br> <span>{</span><br> <span>content</span><span>:</span> url<span>(</span><span>{</span><span>{</span> getSvg<span><span>Url</span><span>(</span>'sv_bbcode_modinterrupt_stop.svg'<span>)</span></span> <span>}</span><span>}</span><span>)</span> <span>!important</span><span>;</span><br> <span>}</span><br> <span><xf:if is="$xf.svg.as.png"><br> .is-tablet &:before,<br> .is-mobile &:before</span><br> <span>{</span><br> <span>content</span><span>:</span> url<span>(</span><span>{</span><span>{</span> <span>getSvgUrlAs</span><span>(</span><span>'sv_bbcode_modinterrupt_stop.svg'</span><span>,</span> <span>'png'</span><span>)</span> <span>}</span><span>}</span><span>)</span> <span>!important</span><span>;</span><br> <span>}</span><br> <<span>/</span><span>xf</span><span>:</span>if><br> <span>}</span><br><span>}</span>
Explicit usage in templates;
XML:
<span><span><span><</span><span>xf:</span>if</span> <span>is</span><span><span>=</span><span>"</span>$xf.svg.enabled<span>"</span></span><span>></span></span><br> <span><span><span><</span><span>xf:</span>if</span> <span>is</span><span><span>=</span><span>"</span>$xf.svg.as.png and $xf.mobileDetect and $xf.mobileDetect.isMobile()<span>"</span></span><span>></span></span><br> <span><span><span><</span>img</span> <span>src</span><span><span>=</span><span>"</span>{{ getSvgUrlAs('example.svg', 'png') }}<span>"</span></span><span>/></span></span><br> <span><span><span><</span><span>xf:</span>else</span> <span>/></span></span><br> <span><span><span><</span>img</span> <span>src</span><span><span>=</span><span>"</span>{{ getSvgUrlAs('example.svg', 'svg') }}<span>"</span></span><span>/></span></span><br> <span><span><span></</span><span>xf:</span>if</span><span>></span></span><br><span><span><span><</span><span>xf:</span>else</span> <span>/></span></span><br> <span><span><span><</span>i</span> <span>class</span><span><span>=</span><span>"</span>fa fa-stop<span>"</span></span> <span>/></span></span><br><span><span><span></</span><span>xf:</span>if</span><span>></span></span>
While webserver rewrite rules are recommended, this add-on supports extending XenForo's routing system to provide zero-configuration support for SVG Templates
Code:
location ^~ /data/svg/ {<br> access_log off;<br> rewrite ^/data/svg/([^/]+)/([^/]+)/([^/]+)/([^\.]+\..*)$ /svg.php?svg=$4&s=$1&l=$2&d=$3$args last;<br> return 403;<br>}
Add the rule before the final index.php;
Code:
RewriteRule ^data/svg/([^/]+)/([^/]+)/([^/]+)/([^\.]+\..*)$ svg.php?svg=$4&s=$1&l=$2&d=$3 [B,NC,L,QSA]
ie, should look similar to;
Code:
# If you are having problems with the rewrite rules, remove the "#" from the<br> # line that begins "RewriteBase" below. You will also have to change the path<br> # of the rewrite to reflect the path to your XenForo installation.<br> #RewriteBase /xenforo<br><br><br> RewriteCond %{REQUEST_FILENAME} -f [OR]<br> RewriteCond %{REQUEST_FILENAME} -l [OR]<br> RewriteCond %{REQUEST_FILENAME} -d<br> RewriteRule ^.*$ - [NC,L]<br> RewriteRule ^(data/|js/|styles/|install/|favicon\.ico|crossdomain\.xml|robots\.txt) - [NC,L]<br> RewriteRule ^data/svg/([^/]+)/([^/]+)/([^/]+)/([^\.]+\..*)$ svg.php?svg=$4&s=$1&l=$2&d=$3 [B,NC,L,QSA]<br> RewriteRule ^.*$ index.php [NC,L]
Allows SVG (Scalable Vector Graphics) images to be stored as templates. This creates a new svg.php file in the XF root directory.
To generate a link to an SVG template (The template must have .svg at the end of the name!) ;
Code:
{{ getSvgUrl('tempate.svg') }}
Under Board information, if "Use Full Friendly URLs" (useFriendlyUrls) is set the URL generated is:
Code:
/data/svg/<style_id>/<langauge_id>/<style_last_modified>/<templateName.svg>
Otherwise
Code:
svg.php?svg=<templateName>&s=<style_id>&l=<langauge_id>&d=<style_last_modified>
Rendering SVGs to PNGs requires external support, and depending on OS this may result in odd limitations or poor rendering.
It is not recommended to use Imagick if it can be helped!
Ubuntu (using https://launchpad.net/~ondrej/+archive/ubuntu/php PPA);
Code:
sudo apt install phpX.X-imagick libmagickcore-6.q16-3-extra<br>sudo systemctl restart phpX.X-fpm
*Replace phpX.X with actual PHP version (ie: php8.1 or php8.2 or php8.3)
Note; some distro's require libmagickcore-6.q16-3-extra to be installed to enable SVG support.
Older versions of Imagick have poor SVG support, on top of Imagick's poor security reputation.
This is a generic escape hatch to plug in arbitrary png conversion, using proc_open in php.
Configure Render using proc_open option with;
Code:
<CLI-binary> {destFile} {sourceFile}
{sourceFile} is the source SVG written as a temp file {destFile} is the destination PNG file as a temp file
Alternatively input/output can be done via pipes
Note; template names are only alpha-numeric strings, which is enforced by validation before the CLI option is called
Example using resvg v0.35.0+, configure CLI - Pipe command with;
Code:
/usr/local/bin/resvg --quiet --resources-dir=/tmp/ - -c
Example using resvg, configure CLI command with;
Code:
/usr/local/bin/resvg --quiet {sourceFile} {destFile}
Pre-compiled linux x86_64 binary has been made available here. Compiled on CentOS 7, works on Ubuntu 18.04/20.04/22.04
Compiling may bind to newer versions of glibc which can cause portability issues
Code:
curl https://sh.rustup.rs -sSf | sh<br>source $HOME/.cargo/env<br>cargo install resvg<br>cp ~/.cargo/bin/resvg /usr/local/bin/resvg<br>chmod +x /usr/local/bin/resvg
Note; use snap as otherwise it is likely to have too old an instance!
Code:
sudo snap install inkscape
Configure CLI PIPE command with;
Code:
inkscape --export-type=png -p
An example of conditional CSS to use the png over the svg for mobile clients
Less:
<span>.mod_interrupt--svg.mod_interrupt</span><br><span>{</span><br> <span>&--stop</span><br> <span>{</span><br> <span>&:before</span><br> <span>{</span><br> <span>content</span><span>:</span> url<span>(</span><span>{</span><span>{</span> getSvg<span><span>Url</span><span>(</span>'sv_bbcode_modinterrupt_stop.svg'<span>)</span></span> <span>}</span><span>}</span><span>)</span> <span>!important</span><span>;</span><br> <span>}</span><br> <span><xf:if is="$xf.svg.as.png"><br> .is-tablet &:before,<br> .is-mobile &:before</span><br> <span>{</span><br> <span>content</span><span>:</span> url<span>(</span><span>{</span><span>{</span> <span>getSvgUrlAs</span><span>(</span><span>'sv_bbcode_modinterrupt_stop.svg'</span><span>,</span> <span>'png'</span><span>)</span> <span>}</span><span>}</span><span>)</span> <span>!important</span><span>;</span><br> <span>}</span><br> <<span>/</span><span>xf</span><span>:</span>if><br> <span>}</span><br><span>}</span>
Explicit usage in templates;
XML:
<span><span><span><</span><span>xf:</span>if</span> <span>is</span><span><span>=</span><span>"</span>$xf.svg.enabled<span>"</span></span><span>></span></span><br> <span><span><span><</span><span>xf:</span>if</span> <span>is</span><span><span>=</span><span>"</span>$xf.svg.as.png and $xf.mobileDetect and $xf.mobileDetect.isMobile()<span>"</span></span><span>></span></span><br> <span><span><span><</span>img</span> <span>src</span><span><span>=</span><span>"</span>{{ getSvgUrlAs('example.svg', 'png') }}<span>"</span></span><span>/></span></span><br> <span><span><span><</span><span>xf:</span>else</span> <span>/></span></span><br> <span><span><span><</span>img</span> <span>src</span><span><span>=</span><span>"</span>{{ getSvgUrlAs('example.svg', 'svg') }}<span>"</span></span><span>/></span></span><br> <span><span><span></</span><span>xf:</span>if</span><span>></span></span><br><span><span><span><</span><span>xf:</span>else</span> <span>/></span></span><br> <span><span><span><</span>i</span> <span>class</span><span><span>=</span><span>"</span>fa fa-stop<span>"</span></span> <span>/></span></span><br><span><span><span></</span><span>xf:</span>if</span><span>></span></span>
While webserver rewrite rules are recommended, this add-on supports extending XenForo's routing system to provide zero-configuration support for SVG Templates
Code:
location ^~ /data/svg/ {<br> access_log off;<br> rewrite ^/data/svg/([^/]+)/([^/]+)/([^/]+)/([^\.]+\..*)$ /svg.php?svg=$4&s=$1&l=$2&d=$3$args last;<br> return 403;<br>}
Add the rule before the final index.php;
Code:
RewriteRule ^data/svg/([^/]+)/([^/]+)/([^/]+)/([^\.]+\..*)$ svg.php?svg=$4&s=$1&l=$2&d=$3 [B,NC,L,QSA]
ie, should look similar to;
Code:
# If you are having problems with the rewrite rules, remove the "#" from the<br> # line that begins "RewriteBase" below. You will also have to change the path<br> # of the rewrite to reflect the path to your XenForo installation.<br> #RewriteBase /xenforo<br><br><br> RewriteCond %{REQUEST_FILENAME} -f [OR]<br> RewriteCond %{REQUEST_FILENAME} -l [OR]<br> RewriteCond %{REQUEST_FILENAME} -d<br> RewriteRule ^.*$ - [NC,L]<br> RewriteRule ^(data/|js/|styles/|install/|favicon\.ico|crossdomain\.xml|robots\.txt) - [NC,L]<br> RewriteRule ^data/svg/([^/]+)/([^/]+)/([^/]+)/([^\.]+\..*)$ svg.php?svg=$4&s=$1&l=$2&d=$3 [B,NC,L,QSA]<br> RewriteRule ^.*$ index.php [NC,L]