source: trunk/npemap.org.uk/scripts/tile-processing/makeThumbImage.pl @ 410

Last change on this file since 410 was 410, checked in by Nick Burch, 14 years ago

Add alternate whole-uk image generator script

  • Property svn:executable set to *
File size: 1.6 KB
Line 
1#!/usr/bin/perl
2# Generate the "whole of the UK" thumbnail from lots of files in scaled50
3# Doesn't need corners.csv, but does need scaled50/
4
5use List::Util qw[min max];
6use Image::Magick;
7use strict;
8
9my $tilesize = 125;
10
11my $inscale = 50;
12my $outscale = 125;
13
14my @files = glob("scaled${inscale}/???/???.jpg");
15my %tiles ;
16
17my ($minx, $miny, $maxx, $maxy);
18
19foreach my $f (@files) {
20  $f =~ m/\/(\d+)\/(\d+)\./;
21  my ($x, $y) = ($1 +0, $2 +0);
22  $tiles{$x} ||= {};
23  $tiles{$x}{$y} = $f;
24}
25
26
27$maxx = max(keys %tiles);
28$maxy = max(map { max(keys %{$tiles{$_}})} keys %tiles);
29
30# Decide how big our intermediate, and final images will be
31my $temp_x = $maxx * $tilesize;
32my $temp_y = $maxy * $tilesize;
33
34my $out_x = int($maxx * $tilesize * $inscale / $outscale); 
35my $out_y = int($maxy * $tilesize * $inscale / $outscale);
36
37print "There are $maxx images across, and $maxy images down\n";
38print "The temp image will be $temp_x x $temp_y\n";
39print "The final image will be $out_x x $out_y\n\n";
40
41
42# Render the larger image, where we just include all the scaled images
43my $out = Image::Magick->new(size => $temp_x."x".$temp_y);
44$out ->ReadImage('xc:white');
45
46foreach my $x (1..($maxx)) {
47        foreach my $y (1..($maxy)) {
48                my $input = $tiles{$x}{$y};
49                if(-f $input) {
50                        print "Including $input\n";
51                        my $image = Image::Magick->new;
52            print $image->Read($input);
53            print $out->Composite(image=>$image, x=>(($x-1)*$tilesize), y=>(($y-1)*$tilesize));
54            undef $image;
55        }
56     }
57}
58
59# Now resize it
60$out->Resize("${out_x}x${out_y}");
61$out->Set(quality=>85);
62$out->Write("jpg:thumbnail.jpg");
63undef $out;
64print "($maxx,$maxy)\n";
Note: See TracBrowser for help on using the repository browser.