Skip to content

SpecificationsForImageConversion

John Deck edited this page May 14, 2015 · 3 revisions

This script was written and provided by Joyce Gross for the original MVZ field notebook portal.

#!/usr/bin/perl
#  This script is what was used for the BSCIT/MVZ field notebook page
# usage:
# process.pl v123_s2 v345_s5
#
#### REMEMBER TO COPY THIS SCRIPT TO CHIGNIK IF CHANGES ARE MADE! 
#### This script is not otherwise backed up.
#### on chignik: /data2/notebooks/scripts/from_bufo

#### usage:   ./process.pl v1454_s1 > log 2>&1 &      
####          (this will allow everything to keep running after you close the bufo session)

# Needed for pnm utilties:
$ENV{'LD_LIBRARY_PATH'} = "/usr/local/lib/:/lib:/usr/lib:/usr/local/src/jpeg-6b:/usr/local/netpbm/lib:/usr/X11R6/lib";


$waiting_dir = "/data3/mvzprocessing/notebook/waiting"; # files waiting for processing....
$jpeg_dir = "/data3/mvzprocessing/notebook/jpeg";       # jpeg dir
$tilepic_dir = "/data3/mvzprocessing/notebook/tilepic"; # tilepic dir
$done_dir = "/data3/mvzprocessing/notebook/done";       # move tiffs here (delete later by hand)
$processing_dir = "/data3/mvzprocessing/notebook";      # processing dir (where process.pl is)


$convert = "/usr/local/bin/convert";
$tifftotjp = "/usr/local/bin/tifftotjp";

foreach $dir (@ARGV) {

    # error check? dir name, file names?

    # make jpeg dir
    &make_jpeg_dir($dir);

    # make tilepic dir
    &make_tilepic_dir($dir);

    # make jpegs
    &make_jpegs($dir);

    # make tilepics
    &make_tilepics($dir);

    # move waiting/section dir to done dir
    &move_to_done_dir($dir);
}


sub make_jpeg_dir {
    my ($dir) = @_;
    chdir($jpeg_dir) || die "Can't change to $jpeg_dir ";
    if(!-e $dir) {
        mkdir($dir, 0777) if (! -e) || die "Can't make new $dir directory ";
        `chmod -R a+w $dir`;
    }
    chdir($processing_dir) || die "Can't change to $processing_dir ";
}


sub make_tilepic_dir {
    my ($dir) = @_;
    chdir($tilepic_dir) || die "Can't change to $tilepic_dir ";
    if(!-e $dir) {
        mkdir($dir, 0777) if (! -e) || die "Can't make new $dir directory ";
        `chmod -R a+w $dir`;
    }
    chdir($processing_dir) || die "Can't change to $processing_dir ";
}

sub make_jpegs {
    my ($dir) = @_;
    $tiff_dir = "$waiting_dir"."/$dir";
    chdir($tiff_dir);

    @files = `ls *.tif`;

    foreach $tiff (@files) {

        chomp($tiff);
        if($tiff =~ /\.tif+/) {
            $name = $`;
        }

        # convert tiff to correctly-sized jpeg
        $tiff = "$tiff_dir/$tiff";
        $jpeg = "$jpeg_dir/$dir/$name.jpg";
        $command = "$convert $tiff -resize 640x $jpeg";
        # print "$command\n";
        system($command);

        # bit of error checking
        if(!-e $jpeg) {
            print "jpeg not made: $jpeg\n";
        }

    }
    chdir($processing_dir) || die "Can't change to $processing_dir ";
}

sub make_tilepics {
    my ($dir) = @_;
    $tiff_dir = "$waiting_dir"."/$dir";
    chdir($tiff_dir);
    @files = `ls *.tif`;
    foreach $tiff (@files) {
        chomp($tiff);

        if($tiff =~ /\.tif+/) {
            $name = $`;
        }

        # convert tiff to correctly-sized jpeg
        $tiff = "$tiff_dir/$tiff";
        $tilepic = "$tilepic_dir/$dir/$name.tjp";
        $command = "$tifftotjp -scale 1 $tiff $tilepic";
        # print "$command\n";
        system($command);

        # bit of error checking
        if(!-e $tilepic) {
            print "tilepic not made: $tilepic\n";
        }
    }
    chdir($processing_dir) || die "Can't change to $processing_dir ";
}

sub move_to_done_dir($dir) {
    my ($dir) = @_;
    my $tiff_to_move_dir = "";
    $tiff_to_move_dir = "$waiting_dir"."/$dir";
    `/bin/mv $tiff_to_move_dir $done_dir`;
}

sub strip {  ## strip leading & trailing spaces, reduce internal spaces to one
    my ($foo) = @_;

    $foo =~ s/\s+/ /g;
    $foo =~ s/\s+$//g;
    $foo =~ s/^\s+//g;
    return $foo;
}
Clone this wiki locally