stretching images with ImageMagick convert

stretching images with ImageMagick convert

Post by jeanlutri » Thu, 11 Dec 2003 01:56:02

Hi all,

someone here at work scanned a lot of pictures. The scans are very
good looking but, unfortunately, size do vary a little bit.

It is out of question to rescan all the pictures as they are really
plenty of them and it took lots of time to do (several days actually).

We always keep one copy of the image in really high resolution, uncompressed,
as PNG, in some kind of database.

Then we use those hi-res PNG to generate lots of .JPGs, depending on the
need of our clients (it is, amongst other, for a Web application) and we
keep the hi-res pictures for when we need them.

The problem I have is that, to have some consistency in our pictures
database, I'd like to have all the image having the same width and height.

For the moment, they are all "nearly the same", but not the same.

For example :

[carrera@spyda /home/public/temp/] $ identify Scan000?.tif
Scan0003.tif[1] TIFF 1230x1736 DirectClass 8-bit 6300kb 0.0u 0:01
Scan0006.tif[3] TIFF 1233x1736 DirectClass 8-bit 6300kb 0.0u 0:01
Scan0007.tif[4] TIFF 1237x1736 DirectClass 8-bit 6321kb 0.0u 0:01
Scan0008.tif[5] TIFF 1237x1736 DirectClass 8-bit 6321kb 0.0u 0:01
Scan0009.tif[6] TIFF 1240x1736 DirectClass 8-bit 6336kb 0.0u 0:01

I'd like them all to be, say, 1240x1744, using ImageMagick's convert
command line utility preferably (as all our images are already processed
using ImageMagick utilities).

If I try to "resize", it keeps the width/height ratio.

For example :

$ convert Scan0003.tif -resize 1240x1744 test.tif
$ identify test.tif
test.tif TIFF 1236x1744 DirectClass 8-bit 6322kb 0.0u 0:01

test.tif is 1236x1744 because resize, as explained in the docs, keeps
the "ratio" of the source image.

How can I stretch a picture using ImageMagick's convert utility ? (The
image won't be distorted at all, since it's always only a few pixels
out of 1000+ that are missing).

Thanks in advance for any help,



stretching images with ImageMagick convert

Post by Marco Schm » Sun, 14 Dec 2003 11:35:13

Jean Lutrin:


According to < ; you
will need to use -sample instead of -resize.



stretching images with ImageMagick convert

Post by jeanlutri » Fri, 19 Dec 2003 00:58:19

Hi there,

thanks a lot for your answer, I eventually managed to do it...

After searching a lot in the docs (this info was hard to find), I found
the following :

:By default, the width and height are maximum values. That is, the image
:is expanded or contracted to fit the width and height value while maintaining
:the aspect ratio of the image. Append an exclamation point to the geometry to
:force the image size to exactly the size you specify. For example, if you
:specify 640x480! the image width is set to 640 pixels and height to 480.

So I used both the "-scale" option you proposed and added an exclamation
point (e.g. "-scale 64x90!")... This trick did it ;)