#! @PERL@ -w # This utility is a wrapper around "gs" to convert eps files to the specified # format use strict; use vars qw/ $gs /; use Carp; use Getopt::Long; $gs='@GHOSTSCRIPT@'; sub usage { die "Usage: lr_gsconvert [--resize=w,h] drv infile.eps outfile.xxx\n" . " where \"drv\" is the gs driver used to convert infile.eps\n"; } sub check_file { my $file = $_[0]; die "file does not exist: '$file'\n" unless ( -f $file ); die "file is empty: '$file'\n" unless ( -s $file ); return; } sub bbox_line { my $infile = $_[0]; my $line = undef; open my $fh, $infile or die "could not open '$infile'\n"; while (<$fh>) { $line = $_ if ( $_ =~ m/^\%\%BoundingBox/ ); last if defined $line; } close $fh; die "No BoundingBox found in '$infile'\n" unless defined $line; return $line; } sub scaled_coords { my ( $bbox_coords, $size_coords ) = @_; my @new_size_coords; if ( ( $bbox_coords->[3] / $bbox_coords->[2] ) > ( $size_coords->[1] / $size_coords->[0] ) ) { my $factor = $size_coords->[1] / $bbox_coords->[3]; $new_size_coords[0] = int( $bbox_coords->[2] * $factor ); $new_size_coords[1] = $size_coords->[1]; } else { my $factor = $size_coords->[0] / $bbox_coords->[2]; $new_size_coords[0] = $size_coords->[0]; $new_size_coords[1] = int( $bbox_coords->[3] * $factor ); } return \@new_size_coords; } sub size_params { my ( $infile, $size ) = @_; my $bb_line = bbox_line( $infile ); my @size_coords = split /\,/, $size; die "Invalid number of coordinates in '@size_coords'\n" unless ( @size_coords == 2 ); $bb_line =~ m/^\%\%BoundingBox\:\ (.*)$/; my @bbox_coords = split /\ /, $1; die "Invalid number of coordinates in '@bbox_coords'\n" unless ( @bbox_coords == 4 ); my $new_size_coords = scaled_coords( \@bbox_coords, \@size_coords ); return ' -dEPSFitPage' . ' -dDEVICEWIDTHPOINTS=' . $new_size_coords->[0] . ' -dDEVICEHEIGHTPOINTS='. $new_size_coords->[1]; } sub convert { my ( $driver, $infile, $outfile, $size ) = @_; my $params = '-q -dNOPAUSE -dBATCH'; $params .= ' -sDEVICE=' . $driver; $params .= ' -sOutputFile=' . $outfile; $params .= size_params( $infile, $size ) if defined $size; local $| = 1; print STDERR "lr_gsconvert: generating '$outfile' ($driver)... "; my $code = system("$gs $params $infile"); die "failure\n*** ghostscript execution returned error code $code\n" if $code; print STDERR " done\n"; } sub main { my $driver; my $infile; my $outfile; my $size; GetOptions( "resize=s" => \$size ); if ( @ARGV == 3 ) { $driver = $ARGV[0]; $infile = $ARGV[1]; $outfile = $ARGV[2]; } else { usage(); } check_file( $infile ); convert( $driver, $infile, $outfile, $size ); } main(); __END__ =pod =head1 NAME lr_gsconvert - resize and convert EPS files =head1 SYNOPSIS B [--resize=w,h] I I I =head1 DESCRIPTION B is designed to resize and convert eps files to another format. The I should be one of the drivers available with I. =head1 SEE ALSO gs(1) =head1 AUTHOR Wolfgang Sourdeau =head1 VERSION $Id: lr_gsconvert.in,v 1.2 2006/07/23 13:16:33 vanbaal Exp $ =head1 COPYRIGHT Copyright (C) 2004 Stichting LogReport Foundation LogReport@LogReport.org This program is free software; you can redistribute it and/or modify it 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 program 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 General Public License for more details. You should have received a copy of the GNU General Public License along with this program (see COPYING); if not, check with http://www.gnu.org/copyleft/gpl.html. =cut Local Variables: mode: cperl End: