Jump to content

PHP SVG


shamuraq

Recommended Posts

hi all,

I have seen and sampled many dynamically generated SVG via PHP. What i need to do is

1)save the output as .svg instead of having the svg parsed image still in .php document.

2)save the output .svg to a specific folder in the server.

 

Any suggestions/ideas?

Link to comment
Share on other sites

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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.