/[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

Diff of /openlayers/pdf2tiles.pl

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 21 by dpavlin, Sun Feb 24 23:53:26 2008 UTC revision 22 by dpavlin, Mon Feb 25 00:19:40 2008 UTC
# Line 12  use Data::Dump qw/dump/; Line 12  use Data::Dump qw/dump/;
12    
13  my $pdf = shift @ARGV || die "usage: $0 filename.pdf";  my $pdf = shift @ARGV || die "usage: $0 filename.pdf";
14    
15    my $debug = 1;
16    
17  my $from_page   = 1;  my $from_page   = 1;
18  my $to_page             = 4;  my $to_page             = 4;
19    
# Line 37  $x_res *= ( $to_page - $from_page + 1 ); Line 39  $x_res *= ( $to_page - $from_page + 1 );
39  print "## total size = $x_res*$y_res\n";  print "## total size = $x_res*$y_res\n";
40    
41  # initial width = 2 tiles  # initial width = 2 tiles
42  my $start_dpi = int( 100 / ( $x_res / 512 ) );  my $curr_w = 256 * 2;
43    
44    my $start_dpi = int( 100 / ( $x_res / $curr_w ) );
45    
46  foreach my $zoom ( 1 .. 10 ) {  foreach my $zoom ( 1 .. 10 ) {
47    
# Line 74  foreach my $zoom ( 1 .. 10 ) { Line 78  foreach my $zoom ( 1 .. 10 ) {
78    
79          my $back_color = Imager::Color->new(255, 127, 127);          my $back_color = Imager::Color->new(255, 127, 127);
80    
81          my $img = Imager->new( xsize => $x_size, ysize => $y_size );          sub pad {
82                    my $s = shift;
83                    return 256 - ( $s % 256);
84            }
85    
86            my ( $full_x, $full_y ) = ( $x_size + pad( $x_size ), $y_size + pad( $y_size ) );
87    
88            my $img = Imager->new( xsize => $full_x, ysize => $full_y );
89          $img->box(filled=>1, color=>$back_color);          $img->box(filled=>1, color=>$back_color);
90    
91          my $x_pos = 0;          my $x_pos = int( pad( $x_size ) / 2 );
92            my $y_pos = int( pad( $y_size ) / 2 );
93    
94          foreach my $page_img ( @page_imgs ) {          foreach my $page_img ( @page_imgs ) {
95                  $img->paste( left => $x_pos, top => 0, img => $page_img );                  $img->paste( left => $x_pos, top => $y_pos, img => $page_img );
96                  $x_pos += $page_img->getwidth();                  $x_pos += $page_img->getwidth();
97          }          }
98    
99          undef @page_imgs;          undef @page_imgs;
100    
101            $img->write( file => sprintf("zoom-%03d.jpg", $dpi ) ) if $debug;
102    
103          my $tiles_x = int( $x_size / 256 );          my $tiles_x = int( $x_size / 256 );
104          my $tiles_y = int( $y_size / 256 );          my $tiles_y = int( $y_size / 256 );
105    
106          print "creating in $tiles_x*$tiles_y tiles\n";          print "creating in $tiles_x*$tiles_y tiles from $full_x*$full_y\n";
107    
108          for my $y ( 0 .. $tiles_y ) {          for my $y ( 0 .. $tiles_y ) {
109                  for my $x ( 0 .. $tiles_x ) {                  for my $x ( 0 .. $tiles_x ) {
110    
111                          my $size = {                          my $size = {
112                                  left    => $x * 256,                                  left    => $x * 256,
113                                  bottom  => $y_size - $y * 256,                                  bottom  => $full_y - $y * 256,
114                                  width   => $x == $tiles_x ? $x_size % 256 : 256,                                  width   => 256,
115                                  height  => $y == $tiles_y ? $y_size % 256 : 256,                                  height  => 256,
116                          };                          };
117    
118                          my $tile = $img->crop( %$size ) or die "can't crop $x*$y ",dump( $size );                          my $tile = $img->crop( %$size ) or die "can't crop $x*$y ",dump( $size );
119    
                         if ( ( $x == $tiles_x ) || ( $y == $tiles_y ) ) {  
                                 warn "## expand tile to full size\n";  
                                 my $t2 = Imager->new(xsize => 256, ysize => 256);  
                                 $t2->box(filled=>1, color=>$back_color);  
                                 $t2->paste(  
                                         top => 256 - $size->{height},  
                                         left => 0,  
                                         src => $tile,  
                                 );  
                                 $tile = $t2;  
                         }  
   
120                          # emulate TileCache disk layout                          # emulate TileCache disk layout
121                          my $path = sprintf("%s/%02d/%03d/%03d/%03d/%03d/%03d/%03d.png",                          my $path = sprintf("%s/%02d/%03d/%03d/%03d/%03d/%03d/%03d.png",
122                                  $tiles_path,                                  $tiles_path,
# Line 135  foreach my $zoom ( 1 .. 10 ) { Line 137  foreach my $zoom ( 1 .. 10 ) {
137    
138                          undef $tile;                          undef $tile;
139    
140                          print "# $x*$y -> $path\n";                          printf("# %2d*%-2d -> %s\n", $x, $y, $path);
141    
142                  }                  }
143          }          }

Legend:
Removed from v.21  
changed lines
  Added in v.22

  ViewVC Help
Powered by ViewVC 1.1.26