source: trunk/npemap.org.uk/scripts/tile-processing/thumbnail.pl

Last change on this file was 635, checked in by Dominic Hargreaves, 13 years ago

licence tastic

  • Property svn:executable set to *
File size: 2.2 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# Generate the UK-wide thumbnail image, from corners.csv, and other similar
23#  bits of magic
24
25#my $mode = "rectangle";
26my $mode = "thumb";
27
28
29use Image::Magick;
30
31my $out = Image::Magick->new(size => '700x700');
32
33$out ->ReadImage('xc:white');
34   
35open FH, "<corners.csv" or die "Can't open corners $!";
36
37while(<FH>) {
38    chomp;
39    ($tile, $x, $y) = split /,/, $_;
40    my ($x1, $y1) = ($x, $y);
41    my ($x2, $y2) = ($x+39, ($y-44));
42
43    print "$x,$y2,$x2,$y\n";
44
45    if (($mode eq "rectangle") || (! -f (glob "${tile}_*.jpg")[0])) {   
46       print $out->Draw(primitive => 'rectangle', fill => 'red', points =>"$x1,$y1,$x2,$y2");
47    } else {
48        if (! -f "thumbs/${tile}.jpg") {
49           my $in = Image::Magick->new();
50           $in -> Read((glob "${tile}_*.jpg")[0]);
51           $in -> Sample("160x180");
52           $in -> Write("jpg:thumbs/${tile}.jpg");
53        }
54        my $in = Image::Magick->new();
55        $in -> Read("thumbs/${tile}.jpg");
56        $in -> Sample("40x45");
57        $in->Flip();
58        print $out->Composite(image=>$in, x=>$x1, y=>$y2); 
59    }
60}
61
62close FH;
63
64$out->Flip();
65print $out->Write("jpg:thumbnail.jpg") ;
Note: See TracBrowser for help on using the repository browser.