/[flash]/openlayers/pdf2tiles.pl
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Annotation of /openlayers/pdf2tiles.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 17 - (hide annotations)
Sun Feb 24 12:30:19 2008 UTC (16 years, 2 months ago) by dpavlin
File MIME type: text/plain
File size: 1931 byte(s)
experiment to display redered tiles using openlayers
1 dpavlin 17 #!/usr/bin/perl -w
2    
3     # pdf2tiles.pl
4     #
5     # 02/24/08 01:22:36 CET Dobrica Pavlinusic <dpavlin@rot13.org>
6    
7     use strict;
8    
9     use Imager;
10     use File::Path;
11     use Data::Dump qw/dump/;
12    
13     my $pdf = shift @ARGV || die "usage: $0 filename.pdf";
14    
15     my $limit = '';
16     $limit = '-f 1 -l 1';
17    
18     foreach my $zoom ( 1 .. 12 ) {
19    
20     my $dpi = $zoom * 25;
21    
22     my $ppm = "tmp-$dpi";
23     my $tmp = "$ppm-000001.ppm";
24    
25     print "rendering pdf $pdf in $dpi dpi to $tmp\n";
26    
27     system "pdftoppm $limit -r $dpi -aa yes -aaVector yes $pdf $ppm";
28    
29     die "can't render" unless -f $tmp;
30    
31     my $img = Imager->new;
32     $img->read(file=>$tmp) or die "Can't load $tmp: ", $img->errstr;
33    
34     my $x_size = $img->getwidth();
35     my $y_size = $img->getheight();
36    
37     print "loaded $tmp $x_size*$y_size pixels\n";
38    
39     my $tiles_x = int( $x_size / 256 );
40     my $tiles_y = int( $y_size / 256 );
41    
42     print "creating in $tiles_x*$tiles_y tiles...\n";
43    
44     for my $y ( 0 .. $tiles_y ) {
45     for my $x ( 0 .. $tiles_x ) {
46    
47     my $size = {
48     left => $x * 256,
49     bottom => $y_size - $y * 256,
50     width => $x == $tiles_x ? $x_size % 256 : 256,
51     height => $y == $tiles_y ? $y_size % 256 : 256,
52     };
53    
54     my $tile = $img->crop( %$size ) or die "can't crop $x*$y ",dump( $size );
55    
56     if ( ( $x == $tiles_x ) || ( $y == $tiles_y ) ) {
57     warn "## expand tile to full size\n";
58     my $t2 = Imager->new(xsize => 256, ysize => 256);
59     $t2->paste(
60     top => 256 - $size->{height},
61     left => 0,
62     src => $tile,
63     );
64     $tile = $t2;
65     }
66    
67     # emulate TileCache disk layout
68     my $path = sprintf("tiles/basic/%02d/%03d/%03d/%03d/%03d/%03d/%03d.png",
69     $zoom - 1, # starts with 0
70     int( $x / 1000000 ),
71     int( $x / 1000 ) % 1000,
72     $x % 1000,
73     int( $y / 1000000 ),
74     int( $y / 1000 ) % 1000,
75     $y % 1000
76     );
77    
78     my $dir = $path;
79     $dir =~ s,/[^/]+$,,;
80     mkpath $dir unless -d $dir;
81    
82     $tile->write( file => $path ) or die $tile->errstr;
83    
84     undef $tile;
85    
86     print "# $x*$y -> $path\n";
87    
88     }
89     }
90     }
91    
92    

Properties

Name Value
svn:executable *

  ViewVC Help
Powered by ViewVC 1.1.26