Converting an image into tiles

Note the use of the debian/perl rename, not the redhat one.

  1. Remove spaces, ' and & from the filenames.
    $ rename "s/ /_/g; s/&/and/g; s/'//g " *.pdf
  2. Create jpgs from the pdfs.
    $ for i in *.pdf; do pdfimages -j $i `basename $i .pdf`; done
    $ rm *.pdf
    $ rename 's/-000//' *.jpg
    
  3. Now, for each image... copy it to your working directory, then open it in gimp.
    $ gimp 110_stoke-on-trent.jpg 
  4. Zoom in, 100% should do. Press 1.
  5. Go to the top left of the map (I use the little in the bottom right of the window).
  6. Select the crop tool, then click on the top-left of the map.
  7. Scroll to the right of the map. Set the width to 5000 in the crop window. Adust the hight until the bottom of the selected area hits the top of the map. In this case 53 pixels.
  8. Calculate the angle that this means that the image needs rotating by. TAN is opposite over adjacent. Your opposite is 53, the adjacent is 5000, so the angle that it needs to be rotated by is tan-1(53/5000) = 0.61 degrees.
  9. Select Layer -> Transformation -> Arbitary rotation.
  10. We want to rotate anti-clockwise, so enter the nagative of the angle you came up with in the previous step. Then click rotate. This will take a while.
  11. Crop the image to just the map. You may want a little shear to make this easier.
  12. Resize to 5000x5625. It is probably something like that already. In the case it came out at 4993x5606. You will need to break the link between the width and height. This step also takes a while.
  13. Save your image. CTRL-s. Say export when it asks you how to save it as a jpeg.
  14. Create a directory for the tiles. Name it after the map number.
    $ mkdir 110-tiles
  15. Change to that directory, then run imgsplit.pl.
    $ cd 110-tiles
    $ ../imgsplit.pl ../110_stoke-on-trent.jpg 45 40 
    
  16. Find out what the grid reference of the top left was. This is the original map, not the copy that we edited in Gimp. In this case 360,375.
    $ jpegtran -crop 500x700 ../originals/110_stoke-on-trent.jpg | display -
  17. 375 is the top of the tile in the top left, we want to label ours by the bottom, so subtract 1 to get 374. We then use the rename command again.
    $ rename 's/-(\d+)-(\d+).jpg/sprintf("-%03d-%03d.jpg", ($1+360),(374-$2))/e' tile-*