【发布时间】:2016-10-07 19:20:26
【问题描述】:
使用 Imagick,我将自定义 jpg 放入 svg,然后将它们转换为 jpg。由于 ImageTragick,我放置的 jpeg 永远不会出现,我的字体也不会转换。由于这个漏洞,我的主机升级了他们的 policy.xml,现在它已经坏了。
<policymap>
<!-- <policy domain="system" name="precision" value="6"/> -->
<!-- <policy domain="resource" name="temporary-path" value="/tmp"/> -->
<policy domain="resource" name="memory" value="32MiB"/>
<policy domain="resource" name="map" value="32Mib"/>
<!-- <policy domain="resource" name="area" value="1GB"/> -->
<!-- <policy domain="resource" name="disk" value="16EB"/> -->
<!-- <policy domain="resource" name="file" value="768"/> -->
<policy domain="resource" name="thread" value="1"/> -->
<!-- <policy domain="resource" name="throttle" value="0"/> -->
<policy domain="resource" name="time" value="30"/>
<policy domain="coder" rights="none" pattern="EPHEMERAL" />
<policy domain="coder" rights="none" pattern="URL" />
<policy domain="coder" rights="none" pattern="HTTPS" />
<policy domain="coder" rights="none" pattern="MVG" />
<policy domain="coder" rights="none" pattern="MSL" />
</policymap>
我不知道从哪里开始修复它。我已阅读有关确认图像类型的信息,但对代码的去向感到困惑。
基本上,我指的是我要使用的图像...
$imageURL = $_POST['imageURL'];
然后我使用...构建一个 svg 字符串
$svgString = <<<EOD
<svg class="svgImage" viewBox="0 0 1200 630" preserveAspectRatio="xMidYMin slice">
<image id="placedImage" xlink:href="$imageURL" x="0" y="0" height="630px" width="1200px" />
<text class="newText topText" id="topTextWhite" style="font-size:24px; font-family: impact, sans-serif;" text-anchor="middle" x="600" y="100" fill="black">Test top words</text>
<text class="newText bottomText" id="bottomTextWhite" style="font-size:24px; font-family: impact, sans-serif;" text-anchor="middle" x="600" y="600" fill="black">Test bottom words</text>
</svg>
EOD;
然后准备运行 Imagick()
//NEW FILENAME INCLUDING MICROTIME TO PREVENT DUPLICATIONS
$fileName = "name". microtime(true);
$newFileName = 'gallery/' . $fileName . '.jpg';
//THE FILE WE'LL BE WORKING WITH
$file = 'gallery/' . $fileName . '.svg';
//INITIALIZE STRING FOR PROPER SVG CONVERSION
$current = '<?xml version="1.0" encoding="UTF-8" standalone="no"?>';
//APPEND CONTENT STRING
$current .= $svgString;
//WRITE THE FILE CONTENTS INTO THE FILE
//If file already exists, it will replace it.
file_put_contents($file, $current);
//START CONVERSION PROCESS
$svg = file_get_contents($file);
$image = new Imagick();
$image->setFont("Impact.ttf");
$image->readImageBlob($svg);
$image->setCompression(Imagick::COMPRESSION_JPEG);
$image->setCompressionQuality(60);
$image->setImageFormat("jpg");
$image->writeImage($newFileName);
$image->clear();
$image->destroy();
//DESTROY SVG FILE
unlink($file);
这几个月都很好。现在,转换发生了,但字体不包括在内,放置的图像仅显示为白色背景。在我们有机会实施新解决方案之前,关于如何启动并运行它有什么建议吗?谢谢。
【问题讨论】:
标签: php svg imagemagick imagick imagemagick-convert