Jump to content

PHP SVG


shamuraq

Recommended Posts

Hi Daniel0,

i'm still trying to piece up your reply but am still stuck...

lets just say i have the code below, how do u get them to save the "parsed" svg which is still in .php into a .svg and saved into a certain folder in the server?

<?php
header("Content-type: image/svg+xml");
$output ="<?xml version=\"1.0\" standalone=\"no\"?>";
$output .="<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\"
\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">";

$output .= "<svg width=\"750\" height=\"710\" xmlns=\"http://www.w3.org/2000/svg\" version=\"1.1\">";
//class style sheet
$output .= "<style type=\"text/css\">
<![CDATA[
    .Border { fill:none; stroke:#a4a4a4; stroke-width:1; stroke-dasharray: 5, 3, 9, 2; }
    .Connect { fill:#505050; stroke:#888888; stroke-width:2; opacity:0.7 }
.Connect1 { fill:#FFFFFF stroke:midgrey; stroke-width:1; opacity:0.7 }
.Connect2 { fill:#333333; stroke:#777777; stroke-width:1; opacity:0.7 }
    .SamplePath { fill:none; stroke:#CCCCCC; stroke-width:1 }
    .EndPoint { fill:none; stroke:#888888; stroke-width:2 }
    .CtlPoint { fill:#888888; stroke:none }
    .AutoCtlPoint { fill:none; stroke:blue; stroke-width:4 }
    .Label {font-family: Arial }  
]]>
</style>";
$pattern = array();

for($i = 0; $i<$color1; $i++){
$pattern[$i] = '#FFFFFF';
}
for($i = $color1; $i<$boxes; $i++){
$pattern[$i] = '#666666';
}
shuffle($pattern);
//print_r($pattern);

for($i = 0; $i < $boxes; $i++){
$x = $x + 20;
$a1 = $pattern[$i];

$output .= "<rect style=\"fill:$a1;stroke: #777777\" x=\"$x\" y=\"$y\" width=\"$w\" height=\"$h\">";
$output .= "</rect>";

}
$output .= "</svg>\n";
print $output;
?>

Link to comment
https://forums.phpfreaks.com/topic/184254-php-svg/#findComment-973034
Share on other sites

I don't see why you would be stuck.

 

Take $output and use it with file_put_contents. It doesn't get much easier than that.

file_put_contents('/path/to/folder/on/server/someFile.svg', $output);

 

Just make sure the folder you are writing to has the proper permissions, and you may even want to chmod the file. Otherwise you should be good to go.

Link to comment
https://forums.phpfreaks.com/topic/184254-php-svg/#findComment-973047
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.