Hi, My Svg2AnyFormat-Serializer is now working. I can transform svg to png, jpg, ... .
Still 2 problems remain: 1) How do I pass the format to the module the svg-image should be serialized in. At the moment I have the image-format hardcoded into my module which has been apropriate for my testing purposes. At the moment my httpd.conf looks like the following: -----------------&<----------------- AddHandler axkit .svg RewriteRule ^(.*/perl\/.*).png$ $1.svg [P] <Files ~ *.svg> AxAddStyleMap application/svg2anyformat Apache::AxKit::Language::Svg2AnyFormat AxAddProcessor application/svg2anyformat NULL </Files> -----------------&<----------------- 2) Caching. How do I implement it. Is a small expample out there? thx tom Am Fre, 2003-02-21 um 15.33 schrieb Robin Berjon: > Tom Schindl wrote: > > I've one more question. Is it possible to register a module who are > > called directly in front of the output is send to the client. I've only > > found AxAddOutputTransformer but the registered module one gets ONE > > line, I'd need the complete document. In Cocoon you'd use a serializer > > (e.g. to make JPG out of SVG). Does Axkit provide something similar? > > I think that if your Language modules is last in the chain, it can serialize > whichever way it wants. Be careful to turn charset transcoding off if you're > outputting binary. -- b e s t s o l u t i o n . a t EDV Systemhaus GmbH ------------------------------------------------------------------------ Thomas Schindl Project Management mobile ++43/664/314 59 58 ------------------------------------------------------------------------ Anton-Rauch-Str.6a A-6020 Innsbruck fax ++43/512/935834 http://www.bestsolution.at phone ++43/512/935834
package Apache::AxKit::Language::Svg2AnyFormat;
@ISA = ( 'Apache::AxKit::Language' );
use Apache;
use Image::Magick;
use Apache::Request;
use File::Copy ();
use File::Temp ();
use File::Path ();
use Cwd;
use strict;
my $olddir;
my $tempdir;
my $cache;
sub stylesheet_exists () { 0; }
## ######## TODOS ########
## - making format dynamic
## - add caching
sub handler
{
my $class = shift;
my ( $r, $xml_provider, undef, $last_in_chain ) = @_;
my $format = "png";
my $tempdir = File::Temp::tempdir();
my $image = new Image::Magick();
if ( ! $tempdir )
{
die "Cannot create tempdir: $!";
}
$olddir = cwd;
if( my $dom = $r->pnotes('dom_tree') )
{
my $xmlstring = $dom->toString();
delete $r->pnotes()->{'dom_tree'};
my $fh = Apache->gensym();
chdir( $tempdir ) || fail( "Cannot cd: $!" );
open($fh, ">temp.svg") || fail( "Cannot write: $!" );
print $fh $xmlstring;
close( $fh ) || fail( "Cannot close: $!" );
}
elsif( my $xmlstring = $r->pnotes('xml_string') )
{
my $fh = Apache->gensym();
chdir( $tempdir ) || fail( "Cannot cd: $!" );
open($fh, ">temp.svg") || fail( "Cannot write: $!" );
print $fh $xmlstring;
close( $fh ) || fail( "Cannot close: $!" );
}
else
{
my $text = eval { ${$xml_provider->get_strref()} };
if ($@)
{
my $fh = $xml_provider->get_fh();
chdir($tempdir) || fail("Cannot cd: $!");
File::Copy::copy($fh, "temp.svg");
}
else
{
my $fh = Apache->gensym();
chdir($tempdir) || fail( "Cannot cd: $!" );
open($fh, ">temp.svg") || fail( "Cannot write: $!" );
print $fh $text;
close($fh) || fail("Cannot close: $!");
}
}
chdir( $tempdir ) || fail("Cannot cd: $!");
my $retval = $image->Read( "temp.svg" );
$image->Write( "temp.$format" );
$AxKit::Cfg->AllowOutputCharset(0);
my $pdfh = Apache->gensym();
open( $pdfh, "<temp.$format" ) or fail( "Could not open $format: $!" );
$r->content_type("image/$format");
local $/;
$r->print(<$pdfh>);
return Apache::Constants::OK;
}
sub cleanup {
chdir $olddir;
File::Path::rmtree($tempdir);
}
sub fail {
cleanup();
die @_;
}
1;
__END__
signature.asc
Description: Dies ist ein digital signierter Nachrichtenteil
