Reputation: 345
When i tried to convert this svg into png using PHP imagemagick, it only renders the text in default font only.
is there any way to use the same google font to render the text, when converting into png ?
Any help would greatly be appreceated. Thanks in advance.
SVG file with Sickness font is ok but when render with imagemagick fails. my svg code is:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<?xml-stylesheet type='text/css' href='svg-stylesheet.css' ?>
<svg xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:svg="http://www.w3.org/2000/svg" xmlns="http://www.w3.org/2000/svg" width="250" height="100" version="1.1"><text xml:space="preserve" style="font-size:30px;text-shadow: 1px 1px 1px #CCCCCC;-moz-text-shadow:1px 1px 1px #CCCCCC;-webkit-text-shadow:1px 1px 1px #CCCCCC; fill:#999; font-family:Sickness" x="30" y="70" class="test">
<tspan>Sample TEXT</tspan>
</text>
</svg>
my php code is:
exec('convert -verbose 4.svg -transparent white -quality 100 -alpha on 4.png');
my svg file in here
svg result
png result with imagemagick
Upvotes: 1
Views: 2293
Reputation: 24439
For a custom font outside of your configured type.xml, you'll need to update your $MAGICK_FONT_PATH
environment to include the path to where the font is located. Or just copy the font file to the working directory your executing from. Then it's just a matter of defining the -font
for Imagemagick to use (if it isn't picked up automatically).
// Example with environment path
exec('MAGICK_FONT_PATH=/path/to/sickness convert -font Sickness 4.svg -transparent white -quality 100 -alpha on 4.png');
// Example with ttf in same directory
exec('convert -font Sickness.ttf 4.svg -transparent white -quality 100 -alpha on 4.png');
Other tips & hints here
Upvotes: 3