Depending on configuration, this add-on requires webserver URL rewrite support!
SVG Template
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!) ;
Under Board information, if "Use Full Friendly URLs" (useFriendlyUrls) is set the URL generated is :
Otherwise
Render to PNG
Rendering SVGs to PNGs requires external support, and depending on OS this may result in odd limitations or poor rendering.
php-imagick support
It is not recommended to use Imagick if it can be helped!
Ubuntu (using https://launchpad.net/~ondrej/+archive/ubuntu/php PPA);
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.
CLI support
This is a generic escape hatch to plug in arbitrary png conversion, using proc_open in php.
Configure Render using proc_open option with;
{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
resvg CLI support
Example using resvg, configure CLI command with;
Precompiled binary
Pre-compiled linux x86_64 binary has been made available here. Compiled on CentOS 7, works on Ubuntu 18.04/20.04
Compiling
Compiling may bind to newer versions of glibc which can cause portability issues
Inkscape CLI support
Note; use snap as otherwise it is likely to have too old an instance !
Configure CLI PIPE command with;
Features
Conditional rendering SVGs to PNG (for CSS/LESS)
An example of conditional CSS to use the png over the svg for mobile clients
Explicit usage in templates;
XenForo 2 routing integration
While webserver rewrite rules are recommended, this add-on supports extending XenForo's routing system to provide zero-configuration support for SVG Templates
Nginx URL rewrite config
Apache URL rewrite config
Add the rule before the final index.php;
ie, should look similar to;
Télécharger V2.1.6 :
Version 2.2.0 - Maintainance update :
Require php 7+
Require XenForo 2.1+
Conform XF2.2 support
Minor php 7.0/7.1 compatibility fix
Version 2.2.1 - Bugfix update : Fix "Support SVG url's in XF routing layer" option
Télécharger V2.2.1 :
Version 2.2.2 : Minor code cleanup, avoid connecting to master redis instance to only connect to a replica instance on rendering cached output
Télécharger V2.2.2 :
Version 2.3.0 - Feature update :
Add basic validation that an SVG template should render correctly
Add an optimization pass for SVG's. Prunes pruning whitespace and nodes/attributes known to be safe to remove. Includes minifying any inline css.
Support LESS/CSS in SVG's <style> element.
Add option "Render SVG's as PNG for mobile devices", this supports rewriting calls to getSvgUrl from .svg to .png
Requires Brower Detection v2.1.0+ add-on
Requires updating webserver URL rewrite urls to support PNGs
Caching requires explicitly defining a caching context with the name "sv-svg-img" or "css".
Supports Imagick or CLI executables as a back-end to render SVGs to PNGs.
Using Imagick is not recommended
Example using resvg, as a CLI-executable back-end;
This requires compiling using Rust, or use the pre-compiled linux x86_64 binary here.
Compiling can be done with;
Télécharger V2.3.0 :
Version 2.3.2 - Bugfix update
Require Standard Lib by Xon v1.1.0+
Force usage of global functions so php can optimize them into special bytecode instead of function calls
Fix disabling generating png links if svg => png is not configured
Improve installer to report svg => svg conditions which can block usage
Use "canonical" URL before XF2.2.3 as "full" doesn't work as expected in all contexts
Version 2.3.3 - Maintenance update : Reject attempting to save an SVG template with no elements
Télécharger V2.3.3 :
Version 2.3.4 - Maintenance update : Support
Télécharger V2.3.4 :
Version 2.3.5 - Maintenance update :
Work-around for non-desirable caching behaviour when CloudFlare (or similar) is forced to cache svg.php output
Prevent polluting of caches if the time-stamp is in the future
Télécharger V2.3.5 :
Version 2.4.1 - Maintenance update :
Require XenForo 2.2+
Require StandardLib v1.11.0+
Improve support for rendering templates in the mail & api contexts by correctly injecting template filters/functions into multiple rendering contexts
Compat fix when zlib output compression is enabled for PHP8.0.17+/PHP8.1.4+
Télécharger V2.4.1 :
Version 2.4.2 - Bugfix update :
Fix "XFCP_TemplaterHelper not found" error when upgrading the StandardLib add-on via the GUI
If this has happened, upload the files for this add-on. Then rebuild StandardLib add-on, then run the updater this add-on.
Télécharger V2.4.2 :
Version 2.4.3 - Bugfix update :
Fix issue using
Fix for race condition when creating temp files when encoding svg => png using resvg.
Update README.md to link to updated precompiled binary for resvg (v0.14.1 => v0.23.0)
Télécharger V2.4.3 :
Version 2.4.4 - Maintenance update : Improve error messages when saving invalid SVGs as templates.
Télécharger V2.4.4 :
Version 2.4.5 Bugfix update : Compatibility update with SV/StandardLib v1.14+, still compatible with SV/StandardLib v1.11+
Télécharger V2.4.5 :
Version 2.4.6 Bugfix update :
- Fix template validation ran on the master style instead of the current selected style
- Fix for upcoming XF2.3 compatibility, as Doctrine Cache been documented as being removed.
Télécharger V2.4.6 :
Version 2.4.8 - Bugfix update :
- Fix error running "xf:rebuild-master-data" when the exact template directory structure is missing and the SVG template is the first template compiled for that style.
- Fix possible compatibility issues with other add-ons extending SV/StandardLib's template helper code
Télécharger V2.4.8 :
Version 2.4.9 - Bugfix update :
- Fix SVG template validation was broken which could result in preventing adding a language or style from working correctly (or rebuilding master data)
Télécharger V2.4.9 :
Version 2.5.0 - Maintenance update :
This add-on is now avaliable on atelieraphelion.com
Télécharger V2.5.0 :
Version 2.5.1 - Bugfix update :
- Fix internal server error being generated instead of a 404 when requesting an invalid svg.
Télécharger V2.5.1 :
Version 2.5.2 - Bugfix update :
- Fix "[E_DEPRECATED] strlen(): Passing null to parameter #1 ($string) of type string is deprecated" when attempting to save a new template with an invalid name
Télécharger V2.5.2 :
Version 2.6.0; XF2.3 Compatibility update
Version 2.6.1 - Bugfix update :
- Fix XF2.3 style variations support for getSvgUrl() in style properties
Télécharger V2.6.1 :
Version 2.6.2 - Bugfix update : Provide a better error message when getSvgUrl is used to request a png of an svg when svg => png rendering isn't setup
Télécharger V2.6.2 :
Version 2.6.3 - Bugfix update :
Version 2.7.0 - Feature & Bugfix update :
SVG Template
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') }}
Code:
/data/svg/<style_id>/<langauge_id>/<style_last_modified>/<templateName.svg>
Code:
svg.php?svg=<templateName>&s=<style_id>&l=<langauge_id>&d=<style_last_modified>
Render to PNG
Rendering SVGs to PNGs requires external support, and depending on OS this may result in odd limitations or poor rendering.
php-imagick support
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 php7.4-imagick libmagickcore-6.q16-3-extra
sudo systemctl restart php7.4-fpm
Older versions of Imagick have poor SVG support, on top of Imagick's poor security reputation.
CLI support
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}
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
resvg CLI support
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
Compiling
Compiling may bind to newer versions of glibc which can cause portability issues
Code:
curl https://sh.rustup.rs -sSf | sh
source $HOME/.cargo/env
cargo install resvg
cp ~/.cargo/bin/resvg /usr/local/bin/resvg
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
Code:
inkscape --export-type=png -p
Conditional rendering SVGs to PNG (for CSS/LESS)
An example of conditional CSS to use the png over the svg for mobile clients
Less:
.mod_interrupt--svg.mod_interrupt
{
&--stop
{
&:before
{
content: url({{ getSvgUrl('sv_bbcode_modinterrupt_stop.svg') }}) !important;
}
<xf:if is="$xf.svg.as.png">
.is-tablet &:before,
.is-mobile &:before
{
content: url({{ getSvgUrlAs('sv_bbcode_modinterrupt_stop.svg', 'png') }}) !important;
}
</xf:if>
}
}
XML:
<xf:if is="$xf.svg.enabled">
<xf:if is="$xf.svg.as.png and $xf.mobileDetect and $xf.mobileDetect.isMobile()">
<img src="{{ getSvgUrlAs('example.svg', 'png') }}"/>
<xf:else />
<img src="{{ getSvgUrlAs('example.svg', 'svg') }}"/>
</xf:if>
<xf:else />
<i class="fa fa-stop" />
</xf:if>
While webserver rewrite rules are recommended, this add-on supports extending XenForo's routing system to provide zero-configuration support for SVG Templates
Nginx URL rewrite config
Code:
location ^~ /data/svg/ {
access_log off;
rewrite ^/data/svg/([^/]+)/([^/]+)/([^/]+)/([^\.]+\..*)$ /svg.php?svg=$4&s=$1&l=$2&d=$3$args last;
return 403;
}
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]
Code:
# If you are having problems with the rewrite rules, remove the "#" from the
# line that begins "RewriteBase" below. You will also have to change the path
# of the rewrite to reflect the path to your XenForo installation.
#RewriteBase /xenforo
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^(data/|js/|styles/|install/|favicon\.ico|crossdomain\.xml|robots\.txt) - [NC,L]
RewriteRule ^data/svg/([^/]+)/([^/]+)/([^/]+)/([^\.]+\..*)$ svg.php?svg=$4&s=$1&l=$2&d=$3 [B,NC,L,QSA]
RewriteRule ^.*$ index.php [NC,L]
Télécharger V2.1.6 :
Pour consulter le contenu, vous devez : Se connecter ou S'inscrire.
Version 2.2.0 - Maintainance update :
Require php 7+
Require XenForo 2.1+
Conform XF2.2 support
Minor php 7.0/7.1 compatibility fix
Version 2.2.1 - Bugfix update : Fix "Support SVG url's in XF routing layer" option
Télécharger V2.2.1 :
Pour consulter le contenu, vous devez : Se connecter ou S'inscrire.
Version 2.2.2 : Minor code cleanup, avoid connecting to master redis instance to only connect to a replica instance on rendering cached output
Télécharger V2.2.2 :
Pour consulter le contenu, vous devez : Se connecter ou S'inscrire.
Version 2.3.0 - Feature update :
Add basic validation that an SVG template should render correctly
Add an optimization pass for SVG's. Prunes pruning whitespace and nodes/attributes known to be safe to remove. Includes minifying any inline css.
Support LESS/CSS in SVG's <style> element.
Add option "Render SVG's as PNG for mobile devices", this supports rewriting calls to getSvgUrl from .svg to .png
Requires Brower Detection v2.1.0+ add-on
Requires updating webserver URL rewrite urls to support PNGs
Caching requires explicitly defining a caching context with the name "sv-svg-img" or "css".
Supports Imagick or CLI executables as a back-end to render SVGs to PNGs.
Using Imagick is not recommended
Example using resvg, as a CLI-executable back-end;
/usr/local/bin/resvg --quiet {sourceFile} {destFile}This requires compiling using Rust, or use the pre-compiled linux x86_64 binary here.
Compiling can be done with;
Code:
curl https://sh.rustup.rs -sSf | sh
source $HOME/.cargo/env
cargo install resvg
cp ~/.cargo/bin/resvg /usr/local/bin/resvg
chmod +x /usr/local/bin/resvg
Télécharger V2.3.0 :
Pour consulter le contenu, vous devez : Se connecter ou S'inscrire.
Version 2.3.2 - Bugfix update
Require Standard Lib by Xon v1.1.0+
Force usage of global functions so php can optimize them into special bytecode instead of function calls
Fix disabling generating png links if svg => png is not configured
Improve installer to report svg => svg conditions which can block usage
Use "canonical" URL before XF2.2.3 as "full" doesn't work as expected in all contexts
Version 2.3.3 - Maintenance update : Reject attempting to save an SVG template with no elements
Télécharger V2.3.3 :
Pour consulter le contenu, vous devez : Se connecter ou S'inscrire.
Version 2.3.4 - Maintenance update : Support
getSvgUrlAs('tenplate.svg', 'png') in style propertiesTélécharger V2.3.4 :
Pour consulter le contenu, vous devez : Se connecter ou S'inscrire.
Version 2.3.5 - Maintenance update :
Work-around for non-desirable caching behaviour when CloudFlare (or similar) is forced to cache svg.php output
Prevent polluting of caches if the time-stamp is in the future
Télécharger V2.3.5 :
Pour consulter le contenu, vous devez : Se connecter ou S'inscrire.
Version 2.4.1 - Maintenance update :
Require XenForo 2.2+
Require StandardLib v1.11.0+
Improve support for rendering templates in the mail & api contexts by correctly injecting template filters/functions into multiple rendering contexts
Compat fix when zlib output compression is enabled for PHP8.0.17+/PHP8.1.4+
Télécharger V2.4.1 :
Pour consulter le contenu, vous devez : Se connecter ou S'inscrire.
Version 2.4.2 - Bugfix update :
Fix "XFCP_TemplaterHelper not found" error when upgrading the StandardLib add-on via the GUI
If this has happened, upload the files for this add-on. Then rebuild StandardLib add-on, then run the updater this add-on.
Télécharger V2.4.2 :
Pour consulter le contenu, vous devez : Se connecter ou S'inscrire.
Version 2.4.3 - Bugfix update :
Fix issue using
getSvgUrl/[getSvgUrlAs in style properties with a template without an extension would cause CSS to fail to renderFix for race condition when creating temp files when encoding svg => png using resvg.
Update README.md to link to updated precompiled binary for resvg (v0.14.1 => v0.23.0)
Télécharger V2.4.3 :
Pour consulter le contenu, vous devez : Se connecter ou S'inscrire.
Version 2.4.4 - Maintenance update : Improve error messages when saving invalid SVGs as templates.
Télécharger V2.4.4 :
Pour consulter le contenu, vous devez : Se connecter ou S'inscrire.
Version 2.4.5 Bugfix update : Compatibility update with SV/StandardLib v1.14+, still compatible with SV/StandardLib v1.11+
Télécharger V2.4.5 :
Pour consulter le contenu, vous devez : Se connecter ou S'inscrire.
Version 2.4.6 Bugfix update :
- Fix template validation ran on the master style instead of the current selected style
- Fix for upcoming XF2.3 compatibility, as Doctrine Cache been documented as being removed.
Télécharger V2.4.6 :
Pour consulter le contenu, vous devez : Se connecter ou S'inscrire.
Version 2.4.8 - Bugfix update :
- Fix error running "xf:rebuild-master-data" when the exact template directory structure is missing and the SVG template is the first template compiled for that style.
- Fix possible compatibility issues with other add-ons extending SV/StandardLib's template helper code
Télécharger V2.4.8 :
Pour consulter le contenu, vous devez : Se connecter ou S'inscrire.
Version 2.4.9 - Bugfix update :
- Fix SVG template validation was broken which could result in preventing adding a language or style from working correctly (or rebuilding master data)
Télécharger V2.4.9 :
Pour consulter le contenu, vous devez : Se connecter ou S'inscrire.
Version 2.5.0 - Maintenance update :
This add-on is now avaliable on atelieraphelion.com
- Require php 7.2+
- Require StandardLib v1.18.0+
- If using resvg support, recommend updating to v0.35.0.
Pre-compiled linux x86_64 binary has been made available here.
Compiled on CentOS 7, works on Ubuntu 18.04/20.04/22.04 - Document using resvg v0.35.0+ with "CLI - Pipe" mode, which avoid temporary files when converting SVGs to PNGs
Example using resvg v0.35.0+, configureCLI - Pipecommand with;
Code:
/usr/local/bin/resvg --quiet --resources-dir=/tmp/ - -c
Pour consulter le contenu, vous devez : Se connecter ou S'inscrire.
Version 2.5.1 - Bugfix update :
- Fix internal server error being generated instead of a 404 when requesting an invalid svg.
Télécharger V2.5.1 :
Pour consulter le contenu, vous devez : Se connecter ou S'inscrire.
Version 2.5.2 - Bugfix update :
- Fix "[E_DEPRECATED] strlen(): Passing null to parameter #1 ($string) of type string is deprecated" when attempting to save a new template with an invalid name
Télécharger V2.5.2 :
Pour consulter le contenu, vous devez : Se connecter ou S'inscrire.
Version 2.6.0; XF2.3 Compatibility update
- Requires StandardLib v1.19.0+
- If installed, requires Redis Cache 2.17.0+
- XF2.3 compatibility update
- php 8.4 compatibility fix
Pour consulter le contenu, vous devez : Se connecter ou S'inscrire.
Version 2.6.1 - Bugfix update :
- Fix XF2.3 style variations support for getSvgUrl() in style properties
Télécharger V2.6.1 :
Pour consulter le contenu, vous devez : Se connecter ou S'inscrire.
Version 2.6.2 - Bugfix update : Provide a better error message when getSvgUrl is used to request a png of an svg when svg => png rendering isn't setup
Télécharger V2.6.2 :
Pour consulter le contenu, vous devez : Se connecter ou S'inscrire.
Version 2.6.3 - Bugfix update :
- Fix falsy template name for svg's wasn't supported (ie 0.svg)
- Fix style variant support for
getSvgUrl/getSvgUrlAscould fail when usingproperty_variation()template method
Pour consulter le contenu, vous devez : Se connecter ou S'inscrire.
Version 2.7.0 - Feature & Bugfix update :
- Require StandardLib v1.23.0+
- php 8.4+ compatibility fixes
- Prevent XF2.3 injecting the template name for admins into SVG templates
- Fix separate
<style>chunks in.svgtemplates would get rendered in reverse order - Fix a missing
xmlns=http://www.w3.org/2000/svgattribute on the<svg>tag could cause compatibility issues - Fix
LESSin.svgtemplates wasn't correctly supported, and CSS in a svg template's<style>tag without XML escaped attributes would error. - Add "getSvgAsInlineCss" template method to automate pulling .svg template files and in-lining them into .less templates
Pour consulter le contenu, vous devez : Se connecter ou S'inscrire.
Dernière édition par un modérateur:

