Apache-AxKit-Language-Svg2AnyFormat

 view release on metacpan or  search on metacpan

README  view on Meta::CPAN

Apache-AxKit-Language-Svg2AnyFormat-0.01 version 0.01
=====================================================

This is a addon module to AxKit which can be used as the last
Transformer in the transformer chain to serialize svg to 
jpg, png, gif and pdf. For more informations take a look at the
man pages.

In the example directory you'll find some svg-files which you can
use to test your installation. Most of them are created by a tool
name DrawSWF (http://drawswf.sf.net) which stores its drawings in SVG.

INSTALLATION

To install this module type the following:

lib/Apache/AxKit/Language/Svg2AnyFormat.pm  view on Meta::CPAN

use File::Temp ();
use File::Path ();
use Cwd;
use strict;
use warnings;

my $TEMPDIR_;

my %Config = 
(  
    SVGOutputMimeType   => "image/png",
    SVGOutputSerializer => "ImageMagick"
);

my %MimeTypeSuffixFormatMappings =
(
    "image/png"              => [ "png" , "png"  ],
    "image/jpeg"             => [ "jpg" , "jpeg" ],
    "image/gif"              => [ "gif" , "gif"  ],
    "image/tiff"             => [ "tiff", "tiff" ],
    "application/pdf"        => [ "pdf" , "pdf"  ],
    "application/postscript" => [ "eps" , "eps"  ]
);


sub stylesheet_exists () { 0; }

lib/Apache/AxKit/Language/Svg2AnyFormat.pm  view on Meta::CPAN

    
    require Image::LibRSVG;
    
    my $rsvg = new Image::LibRSVG();
    
    if( Image::LibRSVG->isFormatSupported( $format ) ) {
        if( ! $rsvg->convert( $infile, $converted_file, 0, $format ) ) {
            fail( "The was an error when transforming with Image::LibRSVG\n" );
        }
    } else {
        if( ! $rsvg->convert( $infile, "$TEMPDIR_/temp.png" ) ) {
            fail( "The was an error when transforming with Image::LibRSVG\n" );
        } else {
#	    print STDERR "FORMAT $format NOT SUPPORTED BY Image::LibRSVG\n";
            &serializeWithImageMagick( "$TEMPDIR_/temp.png", $suffix );
        }
    }
    
    return $converted_file;
}

sub serializeWithImageMagick {
    my $infile         = shift;
    my $converted_file = "$TEMPDIR_/temp." . shift;
    my $local_dir;

lib/Apache/AxKit/Language/Svg2AnyFormat.pm  view on Meta::CPAN

        AxKit::Debug(8, "MimeType retrieved from Plugin");
        $mime = $r->pnotes( "axkit_mime_type" );
    } else {
        AxKit::Debug(8, "MimeType retrieved from CONF or using Default");
        $mime = $r->dir_config( "SVGOutputMimeType" ) || $Config{SVGOutputMimeType};
    }
    
    if( ! exists $MimeTypeSuffixFormatMappings{$mime} ) {
        AxKit::Debug(8, "MimeType is not known. We are using DEFAULTS");
        $mime   = $Config{SVGOutputMimeType};
        $suffix = "png";
    } else {
        AxKit::Debug(8, "Setting suffix. To mapped value");
        $suffix = $MimeTypeSuffixFormatMappings{$mime}[0];
    }
    
    return ( $mime, $suffix );
}

sub cleanup {
    File::Path::rmtree( $TEMPDIR_ );

lib/Apache/AxKit/Language/Svg2AnyFormat.pm  view on Meta::CPAN


  <Files ~ *.svg>
    AxAddStyleMap application/svg2anyformat Apache::AxKit::Language::Svg2AnyFormat
    AxAddProcessor application/svg2anyformat NULL

    ## optional with this variable you can
    ## overwrite the default output format 
    ## PNG
    ## Supported Values:
    ##    image/jpeg
    ##    image/png
    ##    image/gif
    ##    application/pdf
    PerlSetVar SVGOutputMimeType image/jpeg
  
    ## optional module to pass the format using cgi-parameters
    ## to the module. For supported values see above
    ## and the man-page of the plugin
    AxAddPlugin Apache::AxKit::Plugin::SvgCgiSerialize   
  </Files>

lib/Apache/AxKit/Language/Svg2AnyFormat.pm  view on Meta::CPAN

  AxAddPlugin Apache::AxKit::Plugin::QueryStringCache

  <Files ~ *.svg>
    AxAddStyleMap application/svg2anyformat Apache::AxKit::Language::Svg2AnyFormat
    AxAddProcessor application/svg2anyformat NULL

    ## optional with this variable you can
    ## overwrite the default output format 
    ## PNG
    ## Supported Values(Native Formats):
    ##    image/png
    ## If you specify any other format:
    ##   svg->png is done by Image::LibRSVG
    ##   png->chosen format Image::Magick
    PerlSetVar SVGOutputMimeType image/jpeg
    
    PerlSetVar SVGOutputSerializer LibRSVG
    
    ## optional module to pass the format using cgi-parameters
    ## to the module. For supported values see above
    ## and the man-page of the plugin
    AxAddPlugin Apache::AxKit::Plugin::SvgCgiSerialize   
  </Files>


=head1 DESCRIPTION

Svg2AnyFormat is a serializer which can transform SVG to many different
output formats(e.g. png, jpg, ... ). At the moment it uses Image::Magick or LibRSVG as conversion libraries
which do not support the whole set of svg features. In one case the conversion
could work in another not. You have to give it a try. Please note because 
Svg2AnyFormat to any format is a searializer it HAS TO BE LAST in the transformer 
chain!!!!

Please note when referencing external material (e.g. Images) you'll have to use an absolute path

=head2 Image::Magick

If no SVGOutputSerializer is set Image::Magick is used as default. The reason is simply

lib/Apache/AxKit/Plugin/SvgCgiSerialize.pm  view on Meta::CPAN


  <Files ~ *.svg>
    AxAddStyleMap application/svg2anyformat Apache::AxKit::Language::Svg2AnyFormat
    AxAddProcessor application/svg2anyformat NULL

    ## optional with this variable you can
    ## overwrite the default output format 
    ## PNG
    ## Supported Values:
    ##    image/jpeg
    ##    image/png
    ##    image/gif
    ##    application/pdf
    PerlSetVar SVGOutputMimeType image/jpeg
  
    ## optional module to pass the format using cgi-parameters
    ## to the module. For supported values see above
    ## and the man-page of the plugin
    AxAddPlugin Apache::AxKit::Plugin::SvgCgiSerialize   
  </Files>

=head1 DESCRIPTION

This plugin reads out the CGI-Parameter mime_type and passes it into the
Module.

=over

=item 

PNG: http://localhost/my.svg?mime_type=image/png

=item 

JPG: http://localhost/my.svg?mime_type=image/jpeg

=item 

GIF: http://localhost/my.svg?mime_type=image/gif

=item 



( run in 0.713 second using v1.01-cache-2.11-cpan-df04353d9ac )