Changeset 10534


Ignore:
Timestamp:
2005-08-19T11:59:48+12:00 (19 years ago)
Author:
chi
Message:

Adding pagedimg types of conversion to PS document.It is through Convert utility of ImageMagick to convert PS documents to different types of image (JPEG, GIF, PNG).

File:
1 edited

Legend:

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

    r10521 r10534  
    323323
    324324    my $success = 0;
     325    $output_type =~ s/.*\-(.*)/$1/i;
     326    # Attempt coversion to Image
     327    if ($output_type =~ /jp?g|gif|png/i) {
     328    $success = &ps_to_img($dirname, $input_filename, $output_filestem, $output_type);
     329    if ($success){
     330        return "item";
     331    }
     332    }
    325333
    326334    # Attempt conversion to TEXT
     
    867875        close ERRLOG;
    868876    }
    869     &util::rm("$output_filestem.html") if (-e "$output_filestem.html");
     877    #&util::rm("$output_filestem.html") if (-e "$output_filestem.html");
    870878    if (-e "$output_filestem.err") {
    871879        if ($faillogfile ne "" && defined(open(FAILLOG,">>$faillogfile")))
     
    11221130
    11231131
     1132# Convert a PS file to various types of image with the convert utility
     1133sub ps_to_img {
     1134    my ($dirname, $input_filename, $output_filestem, $output_type) = @_;
     1135
     1136    # Check that ImageMagick is installed and available on the path (except for Windows 95/98)
     1137    if (!($ENV{'GSDLOS'} eq "windows" && !Win32::IsWinNT())) {
     1138    my $result = `identify 2>&1`;
     1139    if ($? == -1 || $? == 256) {  # Linux and Windows return different values for "program not found"
     1140        #ImageMagick is not installed, thus the convert utility is not available.
     1141        print STDERR "*** ImageMagick is not installed, the convert utility is not available\n";
     1142        return 0;
     1143    }
     1144    }
     1145
     1146    $cmd = "";
     1147    if ($timeout) {$cmd = "ulimit -t $timeout;";}
     1148    $output_type =~ s/.*\_(.*)/$1/i;
     1149    $cmd .= "perl -S pstoimg.pl -convert_to $output_type \"$input_filename\" \"$output_filestem\"";
     1150    if ($ENV{'GSDLOS'} !~ /^windows$/i || $is_winnt_2000) {
     1151    $cmd .= " > \"$output_filestem.out\" 2> \"$output_filestem.err\"";
     1152    } else {
     1153    $cmd .= " > \"$output_filestem.err\"";
     1154    }
     1155
     1156    # don't include path on windows (to avoid having to play about
     1157    # with quoting when GSDLHOME might contain spaces) but assume
     1158    # that the PATH is set up correctly
     1159    $!=0;
     1160    my $retval=system($cmd);
     1161    if ($retval!=0)
     1162    {
     1163    print STDERR "Error executing pstoimg.pl";
     1164    if ($!) {print STDERR ": $!";}
     1165    print STDERR "\n";
     1166    }
     1167   
     1168    #make sure the converter made something
     1169    #if ($retval !=0) || ! -s "$output_filestem")
     1170    if ($retval !=0)
     1171    {
     1172    &util::rm("$output_filestem.out") if (-e "$output_filestem.out");
     1173    #print out the converter's std err, if any
     1174    if (-s "$output_filestem.err") {
     1175        open (ERRLOG, "$output_filestem.err") || die "$!";
     1176        print STDERR "pstoimg error log:\n";
     1177        while (<ERRLOG>) {
     1178        print STDERR "$_";
     1179        }
     1180        close ERRLOG;
     1181    }
     1182    #&util::rm("$output_filestem.html") if (-e "$output_filestem.html");
     1183    if (-e "$output_filestem.err") {
     1184        if ($faillogfile ne "" && defined(open(FAILLOG,">>$faillogfile")))
     1185        {
     1186        open (ERRLOG, "$output_filestem.err");
     1187        while (<ERRLOG>) {print FAILLOG $_;}
     1188        close ERRLOG;
     1189        close FAILLOG;
     1190       }   
     1191        &util::rm("$output_filestem.err");
     1192    }
     1193    return 0;
     1194    }
     1195    &util::rm("$output_filestem.err") if (-e "$output_filestem.err");
     1196    &util::rm("$output_filestem.out") if (-e "$output_filestem.out");
     1197    return 1;
     1198}
     1199
    11241200# Convert any file to HTML with a crude perl implementation of the
    11251201# UNIX strings command.
Note: See TracChangeset for help on using the changeset viewer.