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

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

Make the thumbnail a bit darker, seems to help

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