ImageMagick crop huge image

后端 未结 4 721
南笙
南笙 2020-12-29 17:48

I am trying to create tiles from a huge image say 40000x40000

i found a script on line for imagemagick he crops the tiles. it works fine on small images like say 100

4条回答
  •  太阳男子
    2020-12-29 18:37

    After a lot more digging and some help from the guys on the ImageMagick forum I managed to get it working.

    The trick to getting it working is the .mpc format. Since this is the native image format used by ImageMagick it does not need to convert the initial image, it just cuts out the piece that it needs. This is the case with the second script I setup.

    Lets say you have a 50000x50000 .tif image called myLargeImg.tif. First convert it to the native image format using the following command:

     convert -monitor -limit area 2mb myLargeImg.tif myLargeImg.mpc
    

    Then, run the bellow bash script that will create the tiles. Create a file named tiler.sh in the same folder as the mpc image and put the below script:

     #!/bin/bash
     src=$1
     width=`identify -format %w $src`
     limit=$[$width / 256]
     echo "count = $limit * $limit = "$((limit * limit))" tiles"
     limit=$((limit-1))
     for x in `seq 0 $limit`; do
       for y in `seq 0 $limit`; do
         tile=tile-$x-$y.png
         echo -n $tile
         w=$((x * 256))
         h=$((y * 256))
         convert -debug cache -monitor $src -crop 256x256+$w+$h $tile
       done
     done
    

    In your console/terminal run the below command and watch the tiles appear one at at time into your folder.

     sh ./tiler.sh myLargeImg.mpc
    

提交回复
热议问题