The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Programming Languages
> PHP Development
|
PHP-Image - Problem converting svg to png
Discuss Problem converting svg to png in the PHP Development forum on Dev Shed. Problem converting svg to png PHP Development forum discussing coding practices, tips on PHP, and other PHP-related topics. PHP is an open source scripting language that has taken the web development industry by storm.
|
|
 |
|
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

January 2nd, 2013, 10:41 AM
|
|
Registered User
|
|
Join Date: Jan 2013
Posts: 5
Time spent in forums: 1 h 30 m 31 sec
Reputation Power: 0
|
|
PHP-Image - Problem converting svg to png
Hi all,
I was trying to convert svg to png file using imagemagick. But the font family is not shown correctly after conversion.
the php code I use is
exec("convert -background none path/to/file/test.svg path/to/file/test.png);
whatever the font family in the svg file is, the png file will always show text in "Arial" font. Could anybody tell me how to fix that? Thanks.
|

January 2nd, 2013, 10:43 AM
|
 |
Likely to be eaten by a grue.
|
|
Join Date: Oct 2006
Location: Pennsylvania, USA
|
|
|
imagemagick has nothing to do with PHP (and the code you've pasted is invalid). The imagemagick help boards will be better for you.
__________________
HEY! YOU! Read the New User Guide and Forum Rules
"They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety." -Benjamin Franklin
"The greatest tragedy of this changing society is that people who never knew what it was like before will simply assume that this is the way things are supposed to be." -2600 Magazine, Fall 2002
Think we're being rude? Maybe you asked a bad question or you're a Help Vampire. Trying to argue intelligently? Please read this.
|

January 2nd, 2013, 10:46 AM
|
|
Registered User
|
|
Join Date: Jan 2013
Posts: 5
Time spent in forums: 1 h 30 m 31 sec
Reputation Power: 0
|
|
Quote: | Originally Posted by ManiacDan imagemagick has nothing to do with PHP (and the code you've pasted is invalid). The imagemagick help boards will be better for you. |
But I did got the svg converted except the font.
|

January 2nd, 2013, 10:56 AM
|
|
|
|
yes the above code is in fact "valid" the exec command like a few other simmilar commands in php posts a shell command to the operating system. However it is nothing with your php that needs help with at this point, you need support using the linux/unix application imagemagic
|

January 2nd, 2013, 10:58 AM
|
|
|
However you may want to use the system() command at least while debugging as it will return output from the shell.
Quote: | Originally Posted by portcitysoftwar yes the above code is in fact "valid" the exec command like a few other simmilar commands in php posts a shell command to the operating system. However it is nothing with your php that needs help with at this point, you need support using the linux/unix application imagemagic |
|

January 2nd, 2013, 11:06 AM
|
 |
Likely to be eaten by a grue.
|
|
Join Date: Oct 2006
Location: Pennsylvania, USA
|
|
Quote: | yes the above code is in fact "valid" the exec command like a few other simmilar commands in php posts a shell command to the operating system. | Except the code is not, in fact, valid, since it's missing a closing double-quote.
Quote: | However you may want to use the system() command at least while debugging as it will return output from the shell. |
System OUTPUTS the results directly to the screen, whereas exec() optionally returns the results as an array of lines.
|

January 2nd, 2013, 11:09 AM
|
|
Registered User
|
|
Join Date: Jan 2013
Posts: 5
Time spent in forums: 1 h 30 m 31 sec
Reputation Power: 0
|
|
Quote: | Originally Posted by portcitysoftwar However you may want to use the system() command at least while debugging as it will return output from the shell. |
Ok. Thank you. Could you tell me a way to convert svg to png then?
|

January 2nd, 2013, 11:11 AM
|
|
|
|
sorry missed the quotations. I recommended system while debugging just so he could see the result to see if imagemagic was throwing any errors to the shell.
|

January 2nd, 2013, 11:17 AM
|
|
|
You could try using the imagemagic php extension
PHP Code:
$image = new Imagick();
$image->readImageBlob(file_get_contents('image.svg'));
$image->setImageFormat("png24");
$image->resizeImage(1024, 768, imagick::FILTER_LANCZOS, 1);
$image->writeImage('image.png')
Quote: | Originally Posted by portcitysoftwar sorry missed the quotations. I recommended system while debugging just so he could see the result to see if imagemagic was throwing any errors to the shell. |
|

January 2nd, 2013, 11:18 AM
|
 |
Likely to be eaten by a grue.
|
|
Join Date: Oct 2006
Location: Pennsylvania, USA
|
|
Quote: | Originally Posted by CharlesDou Ok. Thank you. Could you tell me a way to convert svg to png then? | Are you not understanding what we're saying? imagemagick is NOT PHP. We don't know your answer. Use system() or the second argument to exec() to see if your copy of imagemagick is throwing an error. If it is, move on from there. if not, find the imagemagick message board.
|

January 2nd, 2013, 11:22 AM
|
|
|
|
well their is the imagemagic extension of php but it does the same thing and just passes arguments to the shell i do believe.
however your other option would be another conversion library like Apache BATIK Svg Rasterizer
|

January 2nd, 2013, 11:27 AM
|
|
Registered User
|
|
Join Date: Jan 2013
Posts: 5
Time spent in forums: 1 h 30 m 31 sec
Reputation Power: 0
|
|
Quote: | Originally Posted by portcitysoftwar well their is the imagemagic extension of php but it does the same thing and just passes arguments to the shell i do believe.
however your other option would be another conversion library like Apache BATIK Svg Rasterizer |
Thank you for all the replies. I just used the system function to execute the command and it returns 0.
I did use BATIK before but it is too slow. 
|

January 2nd, 2013, 11:37 AM
|
|
|
PHP Code:
<?php
$yourCommand="YOUR COMMAND HERE";
echo '<pre>';
// Outputs all the result of shellcommand "ls", and returns
// the last output line into $last_line. Stores the return value
// of the shell command in $retval.
$last_line = system($yourCommand, $retval);
// Printing additional info
echo '
</pre>
<hr />Last line of the output: ' . $last_line . '
<hr />Return value: ' . $retval;
?>
|

January 2nd, 2013, 11:40 AM
|
|
|
|
try the actual Imagick php extension if that doesnt work then their is really nothing the php guys can help you with as it is an imagemagick application issue. But you may want to make sure you have the correct fonts installled on your system. that should always be the first thing to check when it is defaulting back to arial
|

January 2nd, 2013, 11:40 AM
|
|
|
|
try the actual Imagick php extension if that doesnt work then their is really nothing the php guys can help you with as it is an imagemagick application issue. But you may want to make sure you have the correct fonts installled on your system. that should always be the first thing to check when it is defaulting back to arial
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|