Changeset 17329 for gsdl/trunk/bin


Ignore:
Timestamp:
2008-09-18T14:09:27+12:00 (16 years ago)
Author:
kjdon
Message:

merged pdf_to_img and ps_to_img as the code was pretty much identical

File:
1 edited

Legend:

Unmodified
Added
Removed
  • gsdl/trunk/bin/script/gsConvert.pl

    r17195 r17329  
    294294    # Attempt coversion to Image
    295295    if ($output_type =~ m/jp?g|gif|png/i) {
    296     $success = &pdf_to_img($dirname, $input_filename, $output_filestem, $output_type);
     296    $success = &pdfps_to_img($dirname, $input_filename, $output_filestem, $output_type);
    297297    if ($success){
    298298        return "item";
     
    330330    # Attempt coversion to Image
    331331    if ($output_type =~ m/jp?g|gif|png/i) {
    332     $success = &ps_to_img($dirname, $input_filename, $output_filestem, $output_type);
     332    $success = &pdfps_to_img($dirname, $input_filename, $output_filestem, $output_type);
    333333    if ($success){
    334334        return "item";
     
    10021002# Convert a pdf file to various types of image with the convert command
    10031003
    1004 sub pdf_to_img {
     1004sub pdfps_to_img {
    10051005    my ($dirname, $input_filename, $output_filestem, $output_type) = @_;
    10061006
     
    10101010    if ($? == -1 || $? == 256) {  # Linux and Windows return different values for "program not found"
    10111011        #ImageMagick is not installed, thus the convert utility is not available.
    1012         print STDERR "*** ImageMagick is not installed, the convert utility is not available\n";
     1012        print STDERR "*** ImageMagick is not installed, the convert utility is not available. Unable to convert PDF/PS to images\n";
    10131013        return 0;
    10141014    }
     
    10181018    if ($timeout) {$cmd = "ulimit -t $timeout;";}
    10191019    $output_type =~ s/.*\_(.*)/$1/i;
    1020      $cmd .= "perl -S pdftoimg.pl -convert_to $output_type \"$input_filename\" \"$output_filestem\"";
     1020    $cmd .= "perl -S pdfpstoimg.pl -convert_to $output_type \"$input_filename\" \"$output_filestem\"";
    10211021    if ($ENV{'GSDLOS'} !~ m/^windows$/i || $is_winnt_2000) {
    10221022    $cmd .= " > \"$output_filestem.out\" 2> \"$output_filestem.err\"";
     
    10451045    if (-s "$output_filestem.err") {
    10461046        open (ERRLOG, "$output_filestem.err") || die "$!";
    1047         print STDERR "pdftoimg error log:\n";
     1047        print STDERR "pdfpstoimg error log:\n";
    10481048        while (<ERRLOG>) {
    10491049        print STDERR "$_";
     
    13061306
    13071307
    1308 # Convert a PS file to various types of image with the convert utility
    1309 sub ps_to_img {
    1310     my ($dirname, $input_filename, $output_filestem, $output_type) = @_;
    1311 
    1312     # Check that ImageMagick is installed and available on the path (except for Windows 95/98)
    1313     if (!($ENV{'GSDLOS'} eq "windows" && !Win32::IsWinNT())) {
    1314     my $result = `identify 2>&1`;
    1315     if ($? == -1 || $? == 256) {  # Linux and Windows return different values for "program not found"
    1316         #ImageMagick is not installed, thus the convert utility is not available.
    1317         print STDERR "*** ImageMagick is not installed, the convert utility is not available\n";
    1318         return 0;
    1319     }
    1320     }
    1321 
    1322     $cmd = "";
    1323     if ($timeout) {$cmd = "ulimit -t $timeout;";}
    1324     $output_type =~ s/.*\_(.*)/$1/i;
    1325     $cmd .= "perl -S pstoimg.pl -convert_to $output_type \"$input_filename\" \"$output_filestem\"";
    1326     if ($ENV{'GSDLOS'} !~ m/^windows$/i || $is_winnt_2000) {
    1327     $cmd .= " > \"$output_filestem.out\" 2> \"$output_filestem.err\"";
    1328     } else {
    1329     $cmd .= " > \"$output_filestem.err\"";
    1330     }
    1331 
    1332     # don't include path on windows (to avoid having to play about
    1333     # with quoting when GSDLHOME might contain spaces) but assume
    1334     # that the PATH is set up correctly
    1335     $!=0;
    1336     my $retval=system($cmd);
    1337     if ($retval!=0)
    1338     {
    1339     print STDERR "Error executing pstoimg.pl";
    1340     if ($!) {print STDERR ": $!";}
    1341     print STDERR "\n";
    1342     }
    1343    
    1344     #make sure the converter made something
    1345     #if ($retval !=0) || ! -s "$output_filestem")
    1346     if ($retval !=0)
    1347     {
    1348     &util::rm("$output_filestem.out") if (-e "$output_filestem.out");
    1349     #print out the converter's std err, if any
    1350     if (-s "$output_filestem.err") {
    1351         open (ERRLOG, "$output_filestem.err") || die "$!";
    1352         print STDERR "pstoimg error log:\n";
    1353         while (<ERRLOG>) {
    1354         print STDERR "$_";
    1355         }
    1356         close ERRLOG;
    1357     }
    1358     #&util::rm("$output_filestem.html") if (-e "$output_filestem.html");
    1359     if (-e "$output_filestem.err") {
    1360         if ($faillogfile ne "" && defined(open(FAILLOG,">>$faillogfile")))
    1361         {
    1362         open (ERRLOG, "$output_filestem.err");
    1363         while (<ERRLOG>) {print FAILLOG $_;}
    1364         close ERRLOG;
    1365         close FAILLOG;
    1366        }   
    1367         &util::rm("$output_filestem.err");
    1368     }
    1369     return 0;
    1370     }
    1371     &util::rm("$output_filestem.err") if (-e "$output_filestem.err");
    1372     &util::rm("$output_filestem.out") if (-e "$output_filestem.out");
    1373     return 1;
    1374 }
    1375 
    13761308# Convert any file to HTML with a crude perl implementation of the
    13771309# UNIX strings command.
Note: See TracChangeset for help on using the changeset viewer.