Page 1 of 1

convert: NegativeOrZeroImageSize when resizing / scaling

Posted: 2016-08-05T05:36:24-07:00
by canavan
convert with -resize / -scale aborts with a NegativeOrZeroImageSize error if an image is reduced in size and one dimension is rounded down to zero. I'm using ImageMagick 7.0.2-6 on Ubuntu x64 16.04.

Examples:

Code: Select all

$ convert -size 1000x1 xc:red -resize 49% /tmp/r.png
convert: NegativeOrZeroImageSize `red' @ error/resize.c/ResizeImage/2855.
$ convert -size 1000x1 xc:red -scale 49% /tmp/r.png
convert: NegativeOrZeroImageSize `red' @ error/resize.c/ScaleImage/3225.
$ convert -size 1000x10 xc:red -scale 4% /tmp/r.png
convert: NegativeOrZeroImageSize `red' @ error/resize.c/ScaleImage/3225.
$ convert -size 10x1000 xc:red -scale 4% /tmp/r.png
convert: NegativeOrZeroImageSize `red' @ error/resize.c/ScaleImage/3225.
$ convert -size 10x1000 xc:red -resize 10@ /tmp/r.png
convert: NegativeOrZeroImageSize `red' @ error/resize.c/ResizeImage/2855.

Re: convert: NegativeOrZeroImageSize when resizing / scaling

Posted: 2016-08-05T05:57:59-07:00
by snibgo
Yes, that's what happens. IM won't create images with zero or negative dimensions. This isn't a bug, but by design.

What would you prefer it did instead?

Re: convert: NegativeOrZeroImageSize when resizing / scaling

Posted: 2016-08-08T03:55:43-07:00
by canavan
I'd prefer it to round to 1 instead of 0. Throwing an exception is still OK if the user explicitly specifies a width or height of 0.

This behaviour was considered a bug in the past, for example in viewtopic.php?t=9082