Recent Changes - Search:

Cookbook

PmWiki

pmwiki.org

Svg

Summary: Embedding Scalable Vector Graphics (.SVG) into PmWiki pages
Version: 1
Prerequisites: pmwiki 2
Status:
Maintainer:
Categories: Media, Images

Question

Can Scaleable Vector Graphics (*.svg) be embedded into wiki pages?

Answer

The svg.phpΔ script causes links ending in ".svg" to be converted to embedded svg-grafs (similar to how images are automatically embedded into pages).

If you want up upload svg-files you have to enable the file type by expanding the UploadExts-Array.

 SDVA($UploadExts,array(
  ...
  'svg' => 'image/svg+xml',
  ...
This should be
$UploadExts['svg'] = 'image/svg+xml';
and this should work if set at the beginning of your php module, in immediate execution, so no need to have user to do anything - untested -PRZ

When using this, the %width=% and %height=% WikiStyles have to be placed before the svg file name to define the painting area.

Discussion

Place the svg.phpΔ script in your cookbook/ directory, add the line

include_once('cookbook/svg.php');

to your config.php file, and any link ending in ".svg" will automatically be converted to HTML code for an embedded svg graphic.

Upgrading to Adobe SVG Viewer version 3.03 (use with WinXP/IE) won't display .svg files anymore. PITS 00438 -scoid

Bug Report -- Duplicate Variable Name

This recipe has a "cut and paste" error from the Flash recipe that it was borrowd from. This recipe will conflict with the Flash recipe and the Visio recipe which also has this error.

To address this error, SwfTagFmt must be replaced in the recipe in two places. I suggest using SvgTagFmt or something else the should be relatively unique. This error will cause all the recipes that use this SwfTagFmt variable name to get the mime specific replacement from whichever recipe was loaded last.

Reported by -Kurt Devlin February 16, 2006, at 03:57 PM

Fix proposal with support for alternate content

<?php if (!defined('PmWiki')) exit();
/*  Copyright (C) 2004 Patrick R. Michaud <pmichaud@pobox.com>
    Copyright (C) 2006 Christoph Sommer <http://www.deltadevelopment.de/users/christoph/>

    This file is distributed under the terms of the GNU General Public 
    License as published by the Free Software Foundation; either 
    version 2 of the License, or (at your option) any later version.  

    This module enables embedding of Scaleable Vector Grafics (.svg) files into
    wiki pages.  

    To use this module, simply place this file in the cookbook/ directory
    and add the following line into config.php:

        include_once('cookbook/svg.php');

    You can then embed SVG files into a wiki file by adding lines following
    these examples:

    %width=700 height=300% http://www.example.com/dir/test.svg
    %width=700 height=300% Attach:test.svg
    %width=700 height=300% Attach:test.svg"Alternate Content"
    %width=700 height=300% Attach:test.svg"Attach:test.gif"

*/

// Public recipe information
$RecipeInfo['Svg']['Version'] = '2006-11-22';

// Allow uploading of files ending in .svg or .svgz
$UploadExts['svg'] = 'image/svg+xml';
$UploadExts['svgz'] = 'image/svg+xml';

// Define replacements for SVG ressources
Markup('svg', '<urllink', 
  "/\\b(?>(\\L))([^\\s$UrlExcludeChars]+\\.svg)(\"([^\"]*)\")?/e",
  "Keep(\$GLOBALS['LinkFunctions']['$1'](\$pagename,'$1','$2',NULL,'$1$2',
  '<object type=\'image/svg+xml\' data=\'\$LinkUrl\'>'), 'L').'$4'.Keep('</object>')");

?>

Examples

 %width=700 height=300% http://server/dir/test.svg
 %width=700 height=300% Attach:test.svg

Testfiles

http://upload.wikimedia.org/wikipedia/en/c/ce/SVG-logo.svg

Bug Fixes

The Adove SVG Viewer 3.03 IE problem can be fixed by replacing the last script line with:

 '<object type=\'image/svg+xml\' data=\'\$LinkUrl\'> <param name=\'src\' value=\'\$LinkUrl\'>'), 'L').'$4'.Keep('</object>')");

(added by Lorenz)

To properly handle SVGZ files, the markup declaration must be changed to the following:

 Markup('svg', '<urllink', 
  "/\\b(?>(\\L))([^\\s$UrlExcludeChars]+\\.svgz?)(\"([^\"]*)\")?/e",
  ... 

Contributors

User notes? : If you use, used or reviewed this recipe, you can add your name. These statistics appear in the Cookbook listings and will help newcomers browsing through the wiki.

Edit - History - Print - Recent Changes - Search
Page last modified on January 20, 2012, at 03:51 PM