繁体   English   中英

PHP Imagick SVG 到 PNG 不应用字体

[英]PHP Imagick SVG to PNG not applying font

我正在尝试将包含具有非系统字体的文本的 SVG 文件保存为 PNG。 我已将字体转换为 data64,因为我读到应该绕过需要安装字体的 web 主机。 尽管当我打开创建的 png 时 SVG 在 web 浏览器中正常显示,但显示的文本未应用字体。 我究竟做错了什么...

SVG 数据:

<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" width="3200" height="3200" viewBox="0 0 400 400" xml:space="preserve">
<desc>Created with Fabric.js 3.2.0</desc>
<defs>
    <style type="text/css">
        @font-face {
            font-family: 'ABeeZee';
            src: local('ABeeZee Regular'), local('ABeeZee-Regular'), url(data:font/woff;base64,[[Font Base64 placeholder due to character limit]]) format('woff');
        }
</style>
</defs>
<g transform="matrix(1 0 0 1 200 23.5)" style="font-family:'ABeeZee' !important; ">
        <text xml:space="preserve" font-family="ABeeZee" font-size="32.410852713178286" font-style="normal" font-weight="normal" style="font-family:'ABeeZee' !important; stroke: none; stroke-width: 1; stroke-dasharray: none; stroke-linecap: butt; stroke-dashoffset: 0; stroke-linejoin: miter; stroke-miterlimit: 4; fill: rgb(0,0,0); fill-rule: nonzero; opacity: 1; white-space: pre;"><tspan x="-102.09418605" y="10.18154527">Kent Patrick</tspan></text>
</g>
</svg>

PHP 代码:

$im = new \Imagick();
$im->setBackgroundColor(new \ImagickPixel('transparent'));
$im->readImageBlob( $svg );
$im->setImageFormat( "png24" );
$im->resizeImage( 1000, 1000, \Imagick::FILTER_LANCZOS, 1 );  /*Optional, if you need to resize*/

$im->writeImage( $save_file );

header( 'Content-type: image/png' );
echo $im;

$im->clear();
$im->destroy();

如果您的 SVG 是使用 Fabric JS 创建的,并且我假设您的字体安装在 Canvas 上。 您可以在 Fabric JS 中将 canvas 转换为 PNG。 尝试使用 multipier:2 这可以为您提供更好的图像。

var imgData = canvas.toDataURL({format: 'png', multiplier: 2});

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM