- XF versions
- 2.2+
- 2.3+
- 许可/License
- 无限制/Nulled
根据配置情况,此插件需要 Web 服务器 URL 重写支持!
SVG模板
根据配置,此插件需要 Web 服务器 URL 重写支持!
允许将 SVG(可缩放矢量图形)图像存储为模板。这会在 XF 根目录中创建一个新的 svg.php 文件。
要生成指向 SVG 模板的链接(模板名称必须以 .svg 结尾!)
代码:
{{ getSvgUrl('tempate.svg') }}
在“董事会信息”下,如果设置了“使用完整友好 URL”(useFriendlyUrls),则生成的 URL 为:
代码:
/data/svg/<style_id>/<langauge_id>/<style_last_modified>/<templateName.svg>
否则
代码:
svg.php?svg=<templateName>&s=<style_id>&l=<langauge_id>&d=<style_last_modified>
渲染为PNG格式
将 SVG 渲染为 PNG 需要外部支持,并且根据操作系统的不同,这可能会导致一些奇怪的限制或渲染效果不佳。
php-imagick 支持
如果可以避免,不建议使用Imagick!
Ubuntu(使用launchpad.net PPA)
代码:
sudo apt install php7.4-imagick libmagickcore-6.q16-3-extra
sudo systemctl restart php7.4-fpm
注意:某些发行版需要安装 libmagickcore-6.q16-3-extra 才能启用 SVG 支持。
旧版本的 Imagick 对 SVG 的支持较差,而且 Imagick 的安全声誉也不佳。
命令行支持
这是一个通用的应急方案,用于通过 PHP 中的 proc_open 函数实现任意 PNG 格式转换。
使用 proc_open 选项配置渲染:
代码:
<CLI-binary> {destFile} {sourceFile}
{sourceFile} 是以临时文件形式保存的源 SVG 文件,{destFile} 是以临时文件形式保存的目标 PNG 文件。
或者,也可以通过管道进行输入/输出
。注意:模板名称只能是字母数字字符串,在调用 CLI 选项之前会进行验证以强制执行此要求。
resvg CLI 支持
使用resvg v0.35.0+ 的示例,配置CLI - Pipe命令如下:
代码:
/usr/local/bin/resvg --quiet --resources-dir=/tmp/ - -c
使用resvg 的示例,配置 CLI 命令;
代码:
/usr/local/bin/resvg --quiet {sourceFile} {destFile}
预编译二进制文件
预编译的 Linux x86_64 二进制文件已在此处提供。编译于 CentOS 7,可在 Ubuntu 18.04/20.04/22.04 上运行。
编译
编译过程可能会绑定到较新版本的glibc,这可能会导致可移植性问题。
代码:
curl 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
Inkscape CLI 支持
注意:请使用 snap,否则可能会使用过旧的实例!
代码:
sudo snap install inkscape
配置 CLI PIPE 命令;
代码:
inkscape --export-type=png -p
特点
将 SVG 有条件渲染为 PNG(适用于 CSS/LESS)
以下示例展示了如何使用条件 CSS 在移动客户端上优先显示 PNG 图像而不是 SVG 图像。
较少的:
.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>
XenForo 2 路由集成
虽然建议使用 Web 服务器重写规则,但此插件支持扩展 XenForo 的路由系统,从而为 SVG 模板提供零配置支持。
Nginx URL 重写配置
代码:
location ^~ /data/svg/ {
access_log off;
rewrite ^/data/svg/([^/]+)/([^/]+)/([^/]+)/([^\.]+\..*)$ /svg.php?svg=$4&s=$1&l=$2&d=$3$args last;
return 403;
}
Apache URL 重写配置
在最终的 index.php 文件之前添加该规则;
代码:
RewriteRule ^data/svg/([^/]+)/([^/]+)/([^/]+)/([^\.]+\..*)$ svg.php?svg=$4&s=$1&l=$2&d=$3 [B,NC,L,QSA]
即,应该类似于;
代码:
# 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/svg/([^/]+)/([^/]+)/([^/]+)/([^\.]+\..*)$ svg.php?svg=$4&s=$1&l=$2&d=$3 [B,NC,L,QSA]
RewriteRule ^(data/|js/|styles/|install/|favicon\.ico|crossdomain\.xml|robots\.txt) - [NC,L]
RewriteRule ^.*$ index.php [NC,L]
SVG模板
根据配置,此插件需要 Web 服务器 URL 重写支持!
允许将 SVG(可缩放矢量图形)图像存储为模板。这会在 XF 根目录中创建一个新的 svg.php 文件。
要生成指向 SVG 模板的链接(模板名称必须以 .svg 结尾!)
代码:
{{ getSvgUrl('tempate.svg') }}
在“董事会信息”下,如果设置了“使用完整友好 URL”(useFriendlyUrls),则生成的 URL 为:
代码:
/data/svg/<style_id>/<langauge_id>/<style_last_modified>/<templateName.svg>
否则
代码:
svg.php?svg=<templateName>&s=<style_id>&l=<langauge_id>&d=<style_last_modified>
渲染为PNG格式
将 SVG 渲染为 PNG 需要外部支持,并且根据操作系统的不同,这可能会导致一些奇怪的限制或渲染效果不佳。
php-imagick 支持
如果可以避免,不建议使用Imagick!
Ubuntu(使用launchpad.net PPA)
代码:
sudo apt install php7.4-imagick libmagickcore-6.q16-3-extra
sudo systemctl restart php7.4-fpm
注意:某些发行版需要安装 libmagickcore-6.q16-3-extra 才能启用 SVG 支持。
旧版本的 Imagick 对 SVG 的支持较差,而且 Imagick 的安全声誉也不佳。
命令行支持
这是一个通用的应急方案,用于通过 PHP 中的 proc_open 函数实现任意 PNG 格式转换。
使用 proc_open 选项配置渲染:
代码:
<CLI-binary> {destFile} {sourceFile}
{sourceFile} 是以临时文件形式保存的源 SVG 文件,{destFile} 是以临时文件形式保存的目标 PNG 文件。
或者,也可以通过管道进行输入/输出
。注意:模板名称只能是字母数字字符串,在调用 CLI 选项之前会进行验证以强制执行此要求。
resvg CLI 支持
使用resvg v0.35.0+ 的示例,配置CLI - Pipe命令如下:
代码:
/usr/local/bin/resvg --quiet --resources-dir=/tmp/ - -c
使用resvg 的示例,配置 CLI 命令;
代码:
/usr/local/bin/resvg --quiet {sourceFile} {destFile}
预编译二进制文件
预编译的 Linux x86_64 二进制文件已在此处提供。编译于 CentOS 7,可在 Ubuntu 18.04/20.04/22.04 上运行。
编译
编译过程可能会绑定到较新版本的glibc,这可能会导致可移植性问题。
代码:
curl 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
Inkscape CLI 支持
注意:请使用 snap,否则可能会使用过旧的实例!
代码:
sudo snap install inkscape
配置 CLI PIPE 命令;
代码:
inkscape --export-type=png -p
特点
将 SVG 有条件渲染为 PNG(适用于 CSS/LESS)
以下示例展示了如何使用条件 CSS 在移动客户端上优先显示 PNG 图像而不是 SVG 图像。
较少的:
.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>
XenForo 2 路由集成
虽然建议使用 Web 服务器重写规则,但此插件支持扩展 XenForo 的路由系统,从而为 SVG 模板提供零配置支持。
Nginx URL 重写配置
代码:
location ^~ /data/svg/ {
access_log off;
rewrite ^/data/svg/([^/]+)/([^/]+)/([^/]+)/([^\.]+\..*)$ /svg.php?svg=$4&s=$1&l=$2&d=$3$args last;
return 403;
}
Apache URL 重写配置
在最终的 index.php 文件之前添加该规则;
代码:
RewriteRule ^data/svg/([^/]+)/([^/]+)/([^/]+)/([^\.]+\..*)$ svg.php?svg=$4&s=$1&l=$2&d=$3 [B,NC,L,QSA]
即,应该类似于;
代码:
# 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/svg/([^/]+)/([^/]+)/([^/]+)/([^\.]+\..*)$ svg.php?svg=$4&s=$1&l=$2&d=$3 [B,NC,L,QSA]
RewriteRule ^(data/|js/|styles/|install/|favicon\.ico|crossdomain\.xml|robots\.txt) - [NC,L]
RewriteRule ^.*$ index.php [NC,L]