[Gdal-dev] How to scale an image

Frank Warmerdam warmerdam at pobox.com
Fri Nov 9 10:54:12 EST 2007

Sonson Sonson wrote:
> Hi all,
> I have a question. I would like to know how to scale an image. I am
> writing a program where I need to scale an image before processing it,
> but I cannot find any sample program, or documentation on how to do
> that. Say if my image's size is 6579x3289 pixel and I want it to be
> scaled to 6656x3328, can anybody point me to documentation and sample
> codes on how to do it.


What sort of sampling approach do you want to take?  If you just
want nearest neighbour resampling you can do this as:

   gdal_translate -outsize 6656 3328 in.tif out.tif

or at the API level by specifying 6656,3328 as your buffer size when
doing a RasterIO() to read into memory.

If you want to control the resampling kernel you need to use the warp
api.  At the commandline:

   gdalwarp -rc in.tif out.tif -ts 6656 3328

At the API level it is fairly involved. You could review:


Best regards,
I set the clouds in motion - turn up   | Frank Warmerdam, warmerdam at pobox.com
light and sound - activate the windows | http://pobox.com/~warmerdam
and watch the world go round - Rush    | President OSGeo, http://osgeo.org

More information about the gdal-dev mailing list