Page 1 of 1
How do I best tile a large image?
Posted: 2006-03-20T22:15:20-07:00
by pcreso
Hi,
I have a 450Mb png I want to tile, so I have a 10x10 set of images which make up the original (for a web mapping application).
I tried -crop but the resulting png files failed to display, giving an error about image offest being wrong & the image was outside the area displayed.
I then tried a jpg, but was unable to get zero quality loss, even with -quality 100
The next attempt was a tif output, but I seem to have got a single large tif image built up from the tif tiles instead of the separate image files (at least that is what it looks like from identify's output)
So, any suggestions as to how to best tile the large image, or how to extract the tiff tiles from the composite image?
Thanks,
Brent Wood
Posted: 2006-03-20T22:55:01-07:00
by magick
Try -crop again but add +repage after it so your PNG images will display properly.
Posted: 2006-03-21T20:15:50-07:00
by pcreso
Perfect! Appreciated. I'll post a URL of the mapserver site soon so you can appreciate the results of IM on some 2Gb of mosaiced satellite imagery!
Thanks,
Brent
Posted: 2006-04-27T17:31:26-07:00
by pcreso
Hi,
Appended the script I ran....
To see 3 layers using the images,see
http://203.97.249.147/map_nz/map0.html
click on NZ & zoom in to New Zealand (turn the layers on in the LHS list first) for some local detail in addition to the global imagery
Cheers,
Brent
Code: Select all
#! /bin/bash
# script to tile high res global images
LIST="A1 A2 B1 B2 C1 C2 D1 D2"
for TEXT in $LIST ; do
MAP=world.topo.bathy.200407.3x21600x21600.${TEXT}.png
if [ ! -r tile_${TEXT}.png.0 ] && [ ! -r tile_${TEXT}_00.png ] ; then
echo "Tiling $MAP"
convert $MAP -crop 2160x2160! +repage tile_${TEXT}.png
else
echo "$MAP already tiled"
fi
#rename files if required
echo "Renaming new tiles if required"
if [ -r tile_${TEXT}.png.0 ] ; then
echo "Renaming tiles...."
rm -f files.txt
ls tile_${TEXT}.png.* > files.txt
while read FILE ; do
TILE_NO=`echo "$FILE" | cut -f3 -d"."`
TILE_NAME=`echo "$FILE" | cut -f1 -d"."`
if [ $TILE_NO -le 9 ] ; then
TILE_NO=0$TILE_NO
fi
NEW_NAME=${TILE_NAME}_${TILE_NO}.png
echo "renaming $FILE to $NEW_NAME"
mv $FILE $NEW_NAME
done < files.txt
fi
done
#write world files....
#A1 origin=180, 90
#B1 origin=270, 90
#C1 origin=0, 90
#D1 origin=90, 90
#all x2 files have Y origin of 0, same x origin
X_PIXEL=0.004166666667
Y_PIXEL=-0.004166666667
echo "generating world files"
for TEXT in $LIST ; do
rm -f files.txt
ls tile_${TEXT}*.png > files.txt
if [ "$TEXT" = "A1" ] ; then
X_ORIGIN=180
Y_ORIGIN=90
elif [ "$TEXT" = "A2" ] ; then
X_ORIGIN=180
Y_ORIGIN=0
elif [ "$TEXT" = "B1" ] ; then
X_ORIGIN=270
Y_ORIGIN=90
elif [ "$TEXT" = "B2" ] ; then
X_ORIGIN=270
Y_ORIGIN=0
elif [ "$TEXT" = "C1" ] ; then
X_ORIGIN=0
Y_ORIGIN=90
elif [ "$TEXT" = "C2" ] ; then
X_ORIGIN=0
Y_ORIGIN=0
elif [ "$TEXT" = "D1" ] ; then
X_ORIGIN=90
Y_ORIGIN=90
elif [ "$TEXT" = "D2" ] ; then
X_ORIGIN=90
Y_ORIGIN=0
fi
while read FILE ; do
PREFIX=`echo "$FILE" | cut -f1 -d"."`
PGW=${PREFIX}.pgw
echo "Writing $PGW for $FILE"
ROW=`echo "$FILE" | cut -f3 -d"_" | cut -b1`
COL=`echo "$FILE" | cut -f3 -d"_" | cut -b2`
echo " using row $ROW column $COL"
# get each new tile origin
X_TILE=`echo "1.000000000000 * $X_ORIGIN + ( $COL * 9.0 )" | bc`
Y_TILE=`echo "1.000000000000 * $Y_ORIGIN - ( $ROW * 9.0 )" | bc`
echo " Origin: $X_TILE $Y_TILE"
rm -f $PGW
echo "$X_PIXEL" > $PGW
echo "0" >> $PGW
echo "0" >> $PGW
echo "$Y_PIXEL" >> $PGW
echo "$X_TILE" >> $PGW
echo "$Y_TILE" >> $PGW
done < files.txt
done
Re: How do I best tile a large image?
Posted: 2007-03-21T03:45:01-07:00
by ladyanne
what did the script do ??
and how to use it
Re: How do I best tile a large image?
Posted: 2007-03-21T18:06:59-07:00
by anthony
to discover the basics of cropping an image into multiple tile see
http://www.imagemagick.org/Usage/crop/#crop_tile
Re: How do I best tile a large image?
Posted: 2007-03-22T00:20:07-07:00
by ladyanne
thanks i read it
i crop my image it is not a problem
but this is big image so pb in not the same i need to name it XX_YY.jpg or XX_YY.png
this my probleme to use the small image
but thank for your answer