?? pstoimg
字號(hào):
unless(open(PS,">$tmppsfile") && (print PS $ps) && (close PS)) { if($had_papersize) { print <<"EOF";$prompt: Warning: Could not write "$tmppsfile": $! "$psfile" contains %%Papersize comments. Any of these should be removed else GS will fail.EOF } if($had_nonwhite) { print <<"EOF";$prompt: Warning: Could not write "$tmppsfile": $! "$psfile" has a non-white background. This may cause ugly images.EOF } } $psfile = $tmppsfile; print qq{Debug: Papersize comment in "$psfile" deleted.\n} if($had_papersize && $opt{debug}); print qq{Debug: Background switched to white in "$psfile".\n} if($had_nonwhite && $opt{debug}); } } my $gs_quiet = $opt{debug} ? '' : '-q -dNOPAUSE -dNO_PAUSE'; my $out_redirect = $opt{debug} ? '' : "> $NULLFILE"; my $gs_out = "-sOutputFile=$pnmfile"; my $gsfile = $psfile; # Ghostscript understands only '/' as path delimiter! if($opt{debug}) { print "$prompt: Running $GS $gs_quiet -sDEVICE=$GSDEVICE $gs_size $gs_density $gs_aalias $gs_out $out_redirect\n"; print "GS>$bbx $bby translate\n" if($have_geometry); print "GS>($gsfile) run\n"; print "GS>showpage\n" if ($epsf); print "GS>quit\n"; } open (GS, "|$GS $gs_quiet -sDEVICE=$GSDEVICE $gs_size $gs_density $gs_aalias $gs_out $out_redirect"); print GS "$bbx $bby translate\n" if ($have_geometry); print GS "($gsfile) run\n"; print GS "showpage\n" if ($epsf); print GS "quit\n"; print "\n" if($opt{debug}); unless(close(GS)) { print "$prompt: Error: Ghostscript returned error status ",$?>>8,"\n"; } L2hos->Unlink($psfile) if($ps_changed && !$opt{debug}); 1; }# This sub post-processes the PNM images that come out of Ghostscript.# The image is cropped, flipped and finally converted to PNG or GIF.sub crop_scale_etc { my ($in, $out) = @_; # create temp filename; should be auto-incrementable my $tmp = $in; $tmp =~ s/(\.[^.]*)?$/.t00/; # save the original Ghostscript result if($opt{debug}) { L2hos->Copy($in,$tmp); &increment_name($tmp); } my ($cmd,$type,$width,$height,$just); my $must_align = 0; #$EXTRA_CROP = "a$EXTRA_CROP" # hack to ensure first all-over cropping # unless($EXTRA_CROP =~ /^a/i); # RRM: Remove justification bars $EXTRA_CROP =~ s/h/bt/gi; # crop horizontally $EXTRA_CROP =~ s/v/rl/gi; # crop vertically while ($EXTRA_CROP =~ /([atblrs])/gi) { my $edge = $1; my $croparg = ''; if($edge =~ /b/i) { $croparg = '-bot -sides '; } elsif($edge =~ /[tlr]/i) { $croparg = "-$edge -sides "; } elsif($edge =~ /s/i) { #RRM: shave at most 1-2 rows of white from the bottom if($cmd) { # Terminate command pipe &do_cmd($in,$tmp,$cmd) || return 0; # failure $cmd = ''; } my ($type,$width,$height) = get_image_geometry($in); next unless($type); # skip if no geometry if(&do_cmd_norename("$PNMCROP -bot -sides < $in",$tmp)) { my ($type,$width,$height2) = get_image_geometry($tmp); if($type && ($height - $height2) < 3 ) { # command succeeded and shaved less than 3 rows if($opt{debug}) { L2hos->Copy($tmp,$in); &increment_name($tmp); } else { L2hos->Rename($tmp,$in); } next; } } # MRO: this shouldn't be necessary: L2hos->Unlink($tmp); next; # go to next crop argument } # end switch on crop codes if($cmd) { # Continue command pipe $cmd .= "| $PNMCROP $croparg"; } else { # start new pipe $cmd = "$PNMCROP $croparg< $in "; } } # end cropping if($opt{flip}) { unless($cmd) { $cmd = "$PNMFLIP -$opt{flip} < $in"; } else { $cmd .= "| $PNMFLIP -$opt{flip} "; } } if($RIGHT_JUSTIFY || $TOP_JUSTIFY || $CENTER || $SHORE_UP) { if($cmd) { # empty command pipe, we need the image's geometry &do_cmd($in,$tmp,$cmd); $cmd=''; } # Get bitmap type and dimensions ($type,$width,$height) = &get_image_geometry($in); return 0 unless($type); my ($white_left,$white_right,$white_top,$white_bottom) = (0,0,0,0); if($RIGHT_JUSTIFY || $CENTER) { if($RIGHT_JUSTIFY) { $white_left = int($RIGHT_JUSTIFY-$width); } else { # CENTER $white_left = int(($CENTER-$width) / 2); } $white_left = 0 unless($white_left > 0); $width += $white_left; } if($TOP_JUSTIFY) { if($TOP_JUSTIFY =~ /^x([0-9.]+)/io) { $white_bottom = $1 * $height; } else { $white_bottom = $TOP_JUSTIFY - $height; } if($white_bottom > 0) { $white_bottom = int($white_bottom + 0.99); # round up $height += $white_bottom; } else { $white_bottom = 0; } } if($SHORE_UP =~ /(\d+)(d?)/ && $1) { # RRM: make height and width an exact multiple of $SHORE_UP my ($shoreup,$depth) = ($1,$2); my $extra = $height % $shoreup; if($depth) { # image needs depth, place half the extra space underneath my $bextra = int($extra/2); $white_bottom += $bextra; $white_top += $extra - $bextra; } else { $white_top += $extra; } $extra = $width % $shoreup; my $rextra = int($extra/2); $white_right += $rextra; $white_left += $extra - $rextra; $cmd = ''; } if($white_left) { if($cmd) { &do_cmd($in,$tmp,$cmd) || return 0; } # Start new command pipe $cmd = "$PBMMAKE -white $white_left 1 | $PNMCAT -white -lr - $in "; } if($white_right) { if($cmd) { &do_cmd($in,$tmp,$cmd) || return 0; } # Start new command pipe $cmd = "$PBMMAKE -white $white_right 1 | $PNMCAT -white -lr $in - "; } if($white_top) { if($cmd) { &do_cmd($in,$tmp,$cmd) || return 0; } # Start new command pipe $cmd = "$PBMMAKE -white 1 $white_top | $PNMCAT -white -tb - $in "; } if($white_bottom) { if($cmd) { &do_cmd($in,$tmp,$cmd) || return 0; } # Start new command pipe $cmd = "$PBMMAKE -white 1 $white_bottom | $PNMCAT -white -tb $in - "; } } # endif must_align my $pnmtoimg; if($opt{type} eq 'png') { $pnmtoimg = $PNMTOPNG; if($INTERLACE) { $pnmtoimg .= ' -interlace'; } if($TRANSPARENT) { $pnmtoimg .= ' -trans ' . L2hos->quote($trans_color); } } unless($pnmtoimg) { print qq($prompt: Error: unknown image type "$opt{type}".\n); exit 2; } unless($type) { ($type,$width,$height) = &get_image_geometry($in); return 0 unless($type); } # run ppmquant only on color/gray images if(!$type || $type =~ /(ppm|pgm)/i) { if($cmd) { $cmd .= "| $reduce_color " } else { $cmd = "$reduce_color < $in "; } } if($cmd) { $cmd .= "| $pnmtoimg " } else { $cmd = "$pnmtoimg < $in "; } &do_cmd_norename($cmd,$out) || return 0; print qq{$prompt: Written $out\n} unless($opt{quiet}); 1;}sub banner { print "$prompt V$RELEASE (Revision $VERSION, Perl $])\n";}sub print_version { my $formats = join(',',@IMAGE_TYPES); print <<"EOM";$prompt (Revision $VERSION, perl $]),part of LaTeX2HTML Release V$RELEASE.Supported output image format(s): $formatsEOM 1;}sub print_help { L2hos->perldoc($SCRIPT); 1;}sub print_usage { my $start = 0; my $usage = 'Usage: '; my $indent = ''; print (@_, "\n") if @_; my $perldoc = '/usr/bin'.$dd."perldoc"; my $script = $SCRIPT || $0; open(PIPE, "$perldoc -t $script |") || die "Fatal: can't open pipe: $!"; while (<PIPE>) { if (/^\s*$/) { next; } elsif (/^SYNOPSIS/) { $start = 1; } elsif (/^\w/) { $start = 0; } elsif ($start == 1) { ($indent) = /^(\s*)/; s/^$indent/$usage/; $usage =~ s/./ /g; $start = 2; print $_; } elsif ($start == 2) { s/^$indent/$usage/; print $_; } } close PIPE; 1;}sub do_cmd { my ($in,$tmp,$cmd) = @_; print qq{Running "$cmd > $tmp"\n} if($opt{debug}); my $stat = system("$cmd > $tmp"); if($stat) { # error print qq{$prompt: Error: "$cmd > $tmp" failed: $!\n}; return 0; # failure } elsif(!-s $tmp) { # does not exist or zero size print qq{$prompt: Error: "$cmd > $tmp" produced empty file\n}; L2hos->Unlink($tmp) if(-e $tmp); return 0; # failure } if($opt{debug}) { # increase the temporary filename by 1 # this uses perl's magic autoincrement &increment_name($_[1]); return L2hos->Copy($tmp,$in); } elsif(!L2hos->Rename($tmp,$in)) { print qq{$prompt: Error: rename of "$tmp" to "$in" failed: $!\n}; return 0; # failure } 1;}sub do_cmd_norename { my ($cmd,$out) = @_; print qq{Running "$cmd > $out"\n} if($opt{debug}); my $stat = system("$cmd > $out"); if($stat) { # error print qq{$prompt: Error: "$cmd > $out" failed: $!\n}; return 0; # failure } elsif(!-s $out) { # does not exist or zero size print qq{$prompt: Error: "$cmd > $out" produced empty file\n}; L2hos->Unlink($out) if(-e $out); return 0; # failure } 1;}sub do_cmd_plain { my ($cmd) = @_; print qq{Running "$cmd"\n} if($opt{debug}); my $stat = system($cmd); if($stat) { # error print qq{$prompt: Error: "$cmd" failed: $!\n}; return 0; # failure } 1;}sub get_image_geometry { my ($pnmfile) = @_; my ($type,$width,$height); my $out = `$PNMFILE $pnmfile`; if($? || $out =~ /(P[BGP]M)[^0-9]*(\d+)\s*by\s*(\d+)/i) { $type = $1; $width = $2; $height = $3; print qq{Image "$pnmfile" is $type, ${width}x$height\n} if($opt{debug}); } else { print "$prompt: Error: Could not determine image size: $out\n"; return undef; } ($type,$width,$height);}# push the number in the suffix up one notchsub increment_name { $_[0] =~ s/(\d+)$/$a=$1;++$a/e;}__DATA__=head1 EXAMPLES=over 4=item C<pstoimg foo.ps>Convert the first page of foo.ps to the default bitmap type.=item C<pstoimg -type png -crop a -trans -interlace foo.ps>Same as above, but force png output and crop all the whitespacearound the image and make the color white transparent andgenerate an interlaced bitmap.=item C<pstoimg -multi -out bar -type gif -crop a foo.ps>Consider foo.ps a multiple page PostScript file and create outputfiles bar1.gif, bar2.gif, etc.=back=head1 ENVIRONMENT=over 4=item DENSITY, DEPTH, DEBUG, DISCARDSee B<-density>, B<-depth>, B<-debug>, B<-discard>, respectively.=item GS_LIBThis variable is set to the path(s) where Ghostscript libraries havebeen found on this system during configuration, but only if the built-inpaths are not correct. This fixes the problem of relocation that is quitecommon on Win32 installations. This behavior can be overridden bysetting GS_LIB manually before starting pstoimg.=item LATEX2HTMLDIRThe directory where the LaTeX2HTML library and perl modules are found.Defaults to "/usr/share/latex2html" on this installation.=item OUTFILESetting this has the same effect as specifying B<-out>. Please do not relyon this feature any more, it will disappear from the next releases!=item PAPERSIZEThe papersize to use by Ghostscript to render the image. pstoimg trieshard to optimize for rendering on the smallest possible bitmap size.Still this option is there to enable tuning by hand, although it isdeprecated. If pstoimg finds a better setting, this parameter is ignored.=item SCALESee the discussion of B<-scale>.=item TMP and TEMPUnless overridden by B<-tmp>, these variables denote a directory whereto store temporary files. TMP is considered first, then TEMP.=back=head1 SEE ALSOgs, pnmcrop, pnmquant, pbmmake, pnmcat, pnmfile, pnmflip, ppmtogif,pnmtopng, giftool, giftrans.=head1 NOTESSeveral people have suggested to use ImageMagick's convert instead ofpstoimg. A few comments on this: convert uses (of course) Ghostscript for conversion of PostScript to bitmap, so one still needs gs. Andfor the special requirements of LaTeX2HTML convert's features are notsufficient. The ImageMagick toolset has everything in place, but ithas some overhead that can prove killing when processing some 100 images. pstoimg only does what it really has to, so it should bequite efficient. Don't get me wrong - I like ImageMagick, but not inthe context of LaTeX2HTML.=head1 CAVEATSThis utility is automatically configured and built to work on thelocal setup. If this setup changes (e.g. some of the external commandsare moved), the script has be be reconfigured.Despite the portability of perl, a pstoimg configured on UNIX willprobably not work on Win32 and vice versa.=head1 BUGSThis is a major enhancement release, so there may be a few bugs. Asthe user inteface changed a bit, some of your tools that were usingpstoimg may not work any more. Please report bugs to latex2html@tug.org, stating the (debug) outputof pstoimg, your perl version and the versions of the external tools.Best is to include the cfgcache.pm file from the configuration procedure.=head1 AUTHORMarek Rouchal E<lt>marek@saftsack.fs.uni-bayreuth.deE<gt>=head1 HISTORYThis script went through a long evolution, beginning with a modificationof Doug Crabill's E<lt>dgc@cs.purdue.eduE<gt> ps2epsi script.The first perl version was done by Nikos Drakos <nikos@cbl.leeds.ac.uk>.It was gradually improved by numerous LaTeX2HTML developers:Ross Moore <ross@mpce.mq.edu.au>, Jens Lippmann <lippmann@rbg.informatik.tu-darmstadt.de> and others (sorry for notmentioning everyone and thanks for your contributions).=cut
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -