source: trunk/npemap.org.uk/scripts/tile-processing/assembleTiles.pl @ 699

Last change on this file since 699 was 699, checked in by Nick Burch, 10 years ago

Add script for assembling a directory of tiles back into one file

  • Property svn:eol-style set to native
  • Property svn:executable set to *
File size: 2.4 KB
Line 
1#!/usr/bin/perl
2#
3# Copyright (c) 2006 David Sheldon and Nick Burch
4# Permission is hereby granted, free of charge, to any person obtaining a
5# copy of this software and associated documentation files (the "Software"),
6# to deal in the Software without restriction, including without limitation
7# the rights to use, copy, modify, merge, publish, distribute, sublicense,
8# and/or sell copies of the Software, and to permit persons to whom the
9# Software is furnished to do so, subject to the following conditions:
10#
11# The above copyright notice and this permission notice shall be included in
12# all copies or substantial portions of the Software.
13#
14# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
20# IN THE SOFTWARE.
21#
22# Takes a directory full of tile images, and assembles them back into a
23#  single large image.
24# Normally run against a map tiles directory, eg 107-tiles-1947
25
26use strict;
27use Image::Magick;
28
29# How big an image do we want?
30my @files = glob("tile-*.jpg");
31my @eastings  = sort map { /^tile-(\d+)-\d+\.jpg$/ } @files;
32my @northings = sort map { /^tile-\d+-(\d+)\.jpg$/ } @files;
33unless(@files) {
34        die("Failed to find files of the form <tile-nnn-nnn.jpg> in the current directory\n");
35}
36
37my $min_easting = $eastings[0];
38my $max_easting = $eastings[-1];
39my $min_northing = $northings[0];
40my $max_northing = $northings[-1];
41
42my $num_easting = $max_easting - $min_easting + 1;
43my $num_northing = $max_northing - $min_northing + 1;
44
45my $size_x = $num_easting * 125;
46my $size_y = $num_northing * 125;
47
48# Start to assemble
49my $out = Image::Magick->new(size => $size_x."x".$size_y);
50$out ->ReadImage('xc:white');
51
52my $count = 0;
53foreach my $file (@files) {
54        my ($e,$n) = ($file =~ /^tile-(\d+)-(\d+)\.jpg$/);
55        my $rel_e = $e - $min_easting;
56        my $rel_n = $n - $min_northing;
57        my $bl_x = $rel_e * 125;
58        my $bl_y = $rel_n * 125;
59
60        my $in = Image::Magick->new();
61        $in->Read($file);
62        $in->Flip();
63        print $out->Composite(image=>$in, x=>$bl_x, y=>$bl_y); 
64
65        $count++;
66        if($count % 100 == 0) {
67                print "Done $count files\n";
68        }
69}
70   
71$out->Flip();
72print $out->Write("jpg:joined.jpg") ;
Note: See TracBrowser for help on using the repository browser.