tips:svg.php
svg.php
This is a plugin to DokuWiki to allow collaborative generation of SVG images.
- svg.php
<?php /** * SVG Convert - Calling function * Copyright (C) 2005 Chris Lee <wiki@chrislee.dhs.org> * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * -------------------------------------------------------------------- * @author Chris Lee <wiki@chrislee.dhs.org> * @version v0.1 * @package svgconvert * This file can be included in many PHP programs by using something like (see example.php to see how it can be used) * include_once('/full_path_here_to/svgconvert/svg.php'); * $text_to_be_converted=svg_content($text_to_be_converted); * $text_to_be_converted will then contain the link to the appropriate image * or an error message. */ function svg_content($text) { global $conf; $svgconvert_path = "/opt/lampp/htdocs/hosts/chrislee.dhs.org/html/wiki/inc/svgconvert"; $svgconvert_path_http = "/wiki/media/svgconvert"; $svgconvert_media_path = "/opt/lampp/htdocs/hosts/chrislee.dhs.org/html/wiki/media/svgconvert"; $ImageMagick_convert = "/usr/bin/convert"; $filename = md5($text).".gif"; $localfile = "$svgconvert_media_path/$filename"; $tempfile = $svgconvert_path."/tmp/".$filename.".svg"; $url = $svgconvert_path_http."/".$filename; if ( file_exists( $localfile ) ) return ( "<img src='$url' align=absmiddle>" ); else { $fp = fopen( $tempfile, 'w' ); fputs( $fp, $text ); fclose( $fp ); exec( "$ImageMagick_convert $tempfile $localfile" ); unlink( $tempfile ); if ( file_exists( $localfile ) ) return ( "<img src='$url' align=absmiddle>" ); else return ( "Could not create SVG Image<br/>\n" ); } } ?>
There are nicer ways to generate SVG files… e.g.:
?><svg width="640" height="480" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns="http://www.w3.org/2000/svg"> <!-- Created with SVG-edit - http://svg-edit.googlecode.com/ --> <g> <title>Layer 1</title> <text xml:space="preserve" text-anchor="middle" font-family="serif" font-size="24" stroke-width="0" stroke="#000000" fill="#000000" id="svg_3" y="362" x="115"><?php echo(htmlspecialchars($text)); ?></text> </g> </svg><?php
btw i am thinking about embedding SVG-edit to DokuWiki WYSIWYG, so the SVG file will be saved as a DokuWiki page and embedded to another using &do=export_raw…
tips/svg.php.txt · Last modified: 2010-02-22 19:36 by 74.93.99.97