Changeset 409


Ignore:
Timestamp:
Dec 9, 2006, 4:56:21 PM (13 years ago)
Author:
Nick Burch
Message:

Create the output directories if they don't already exist

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/npemap.org.uk/scripts/tile-processing/makeSmaller.pl

    r407 r409  
    2525  $tiles{$x} ||= {};
    2626  $tiles{$x}{$y} = $f;
    27 
    2827}
    2928
     
    3736foreach my $x (0..($maxx/$scale)) {
    3837    foreach my $y (0..($maxy/$scale)) {
    39       my $filename = sprintf("%s/%03d/%03d.jpg", $outdir,$x,$y);
    40       if ((! -f $filename) && any_tiles($x, $y, \%tiles) ) {
    41                 print "Making $filename\n";
    42          my $out = Image::Magick->new(size => ($tilesize * $scale). "x".($tilesize *$scale));
    43          $out ->ReadImage('xc:white');
     38        my $filename = sprintf("%s/%03d/%03d.jpg", $outdir, $x, $y);
     39        my $outdir = sprintf("%s/%03d/", $outdir, $x);
     40               
     41
     42        if( (! -f $filename) && any_tiles($x, $y, \%tiles) ) {
     43            print "Making $filename\n";
     44            my $out = Image::Magick->new(size => ($tilesize * $scale). "x".($tilesize *$scale));
     45            $out ->ReadImage('xc:white');
     46
     47            unless(-d $outdir) {
     48                mkdir($outdir);
     49            }
     50
    4451 foreach my $i (0..($scale -1)) {
    4552     foreach my $j (0..($scale -1)) {
    4653         if (defined $tiles{($x*$scale)+$i}{($y*$scale)+$j}) {
    4754            my $image = Image::Magick->new;
    48             print $image->Read($tiles{($x*$scale)+$i}{($y*$scale)+$j});
     55            my $input = $tiles{($x*$scale)+$i}{($y*$scale)+$j};
     56                        #print "  Including $input\n";
     57
     58            print $image->Read($input);
    4959            print $out->Composite(image=>$image, x=>($i*$tilesize), y=>((($scale -1)-$j)*$tilesize));
    5060            undef $image;
     
    5262     }
    5363 }
    54  $out->Resize("${tilesize}x$tilesize");
    55  $out->Set(quality=>85);
    56  $out->Write("jpg:$filename");
    57  undef $out;
    58           print "($x,$y)\n";
    59        
    60       }
    61     }
     64
     65            $out->Resize("${tilesize}x$tilesize");
     66            $out->Set(quality=>85);
     67            $out->Write("jpg:$filename");
     68            undef $out;
     69            print "($x,$y)\n";
     70        }
     71   }
    6272}
    6373
Note: See TracChangeset for help on using the changeset viewer.