unexpected error "convert: geometry does not contain image"

Post any defects you find in the released or beta versions of the ImageMagick software here. Include the ImageMagick version, OS, and any command-line required to reproduce the problem. Got a patch for a bug? Post it here.
alex_nb

unexpected error "convert: geometry does not contain image"

Post by alex_nb »

Hello,
trying to execute a command like this:

convert res.jpg '-crop' '100x235+200+102' '-resize' '300x705!' '-crop' '300x300+0+0' test.jpg

I get the error:
convert: geometry does not contain image `res.jpg' @ transform.c/CropImage/507.

but I think it's a bug, in fact if I issue the command in two phases, for example:
convert res.jpg '-crop' '100x235+200+102' '-resize' '300x705!' tmp.jpg
convert tmp.jpg '-crop' '300x300+0+0' test.jpg
everything works fine

Did I miss something?
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: unexpected error "convert: geometry does not contain image"

Post by magick »

Add +repage to your command line. Does that fix the problem?
alex_nb

Re: unexpected error "convert: geometry does not contain image"

Post by alex_nb »

Hello and thanks for your answer, that seems to fix the problem.

Anyway I can't understand why I should use it explicitly, shouldn't it be automatic?

Since the commandline is automatically generated I added a +repage before every operation, it seems to work fine but do you think that could cause any kind of problems?

Thanks,
Alex
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: unexpected error "convert: geometry does not contain image"

Post by anthony »

If it was automatic, then you lose information that is vital to many other image processing tasks. Especially with regards to layering images, and animations.

See IM Examples, The Missed Image (from a bad crop)
http://www.imagemagick.org/Usage/crop/#crop_missed
for details.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
dahans
Posts: 2
Joined: 2013-02-28T03:06:19-07:00
Authentication code: 6789

Re: unexpected error "convert: geometry does not contain ima

Post by dahans »

Hi, i read many times about this problem and now i run in for myself, i tried anything to solve this problem but without success

the error : convert: geometry does not contain image `picture.png' @ warning/attribute.c/GetImageBoundingBox/244.
throws when im running this command: convert 'picture.png' -trim -profile 'sRGB.icc' -verbose 'image.png'
the output was: picture.png=>image.png PNG 970x1261=>1x1 970x1261-1-1 8-bit sRGB 2c 0.080u 0:00.079

all attempts by adding +repage without success


Edit:
Version: ImageMagick 6.8.0-7 2013-02-27 Q16
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: unexpected error "convert: geometry does not contain ima

Post by snibgo »

1x1 970x1261-1-1
You have trimmed the image to nothing, zero size.
snibgo's IM pages: im.snibgo.com
dahans
Posts: 2
Joined: 2013-02-28T03:06:19-07:00
Authentication code: 6789

Re: unexpected error "convert: geometry does not contain ima

Post by dahans »

it is not able to save empty images ?
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: unexpected error "convert: geometry does not contain ima

Post by snibgo »

Sadly, no.

I think it should handle zero images, in the same way that arithmetic can handle zero numbers. I think I read that version 7 will be able to do so.
snibgo's IM pages: im.snibgo.com
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: unexpected error "convert: geometry does not contain ima

Post by magick »

Its probably not difficult to support "zero" images. Can you post a few use cases where you would use "zero" images but fail to work now? What are some specific command-line examples that produce an exception rather than a zero image? We'll use these examples to test our patches to support "zero" images.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: unexpected error "convert: geometry does not contain ima

Post by snibgo »

Here is a Windows script of some examples, off the top of my head. In each example, I've added a comment about whether I think the result is correct.

It seems IM mostly handles zero images appropriately. It may throw a warning, but not an error. (I note that the OP had a warning, not an error.)

Hence, I mostly retract my comment above: I now think IM does (mostly) handle zero images correctly.

Code: Select all

set IP=%IMG683%

"%IP%convert" ^
  -size 100x100 xc:Red -trim ^
  zeroA.png
rem
rem No problem.

"%IP%convert" ^
  -size 100x100 xc:Red -trim ^
  -unique-colors ^
  zeroB.png
rem
rem No problem.

"%IP%convert" ^
  -size 100x100 xc:Red ^
  ( +clone -trim ) ^
  -composite ^
  shouldBeRed.png
rem
rem No problem.

"%IP%convert" ^
  zeroA.png ^
  -resize "100x200^!" ^
  zeroResized.png
"%IP%identify" zeroResized.png
rem
rem No problem.

"%IP%convert" ^
  -size 100x100 xc:Red ^
  -remap zeroB.png ^
  weird.png
"%IP%identify" weird.png
rem
rem weird.png is black. I'm not sure if this is reasonable.

"%IP%convert" ^
  -size 100x100 xc:Red ^
  zeroA.png ^
  -compose Divide_Src -composite ^
  divideZero.png
rem
rem divideZero.png is 100x100 Red, which is reasonable.

"%IP%convert" ^
  -size 100x100 xc:Red ^
  zeroA.png ^
  -compose Multiply -composite ^
  multiplyZero.png
rem
rem multiplyZero.png is 100x100 Red, which is reasonable.

"%IP%convert" ^
  -size 100x100 xc:Red ^
  zeroA.png ^
  -compose Add -composite ^
  addZero.png
rem
rem addZero.png is 100x100 Red, which is reasonable.

"%IP%convert" ^
  -size 100x100 xc:Red ^
  zeroA.png ^
  -compose Difference -composite ^
  differenceZero.png
rem
rem differenceZero.png is 100x100 Red, which is reasonable.

"%IP%convert" ^
  -size 100x100 xc:Red ^
  zeroA.png ^
  -compose Displace -composite ^
  displaceZero.png
"%IP%identify" displaceZero.png
rem
rem displaceZero.png is roughly black, but should be 100x100 Red


"%IP%composite" ^
  -size 100x100 xc:Red ^
  zeroA.png ^
  -displace 10x20 ^
  badResult.png

"%IP%identify" badResult.png
rem
rem badResult is zero image but should be 100x100 Red

"%IP%convert" ^
  zeroA.png ^
  txt:
rem
rem Output is one pixel (transparent white). Output should be no pixels.
EDIT: correction to my comment to the last example: the output is transparent white, not transparent black.
snibgo's IM pages: im.snibgo.com
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: unexpected error "convert: geometry does not contain ima

Post by magick »

Stand by, we'll investigate the issue.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: unexpected error "convert: geometry does not contain ima

Post by snibgo »

I don't know what file formats support zero images. If a format mandates a minimum size 1x1, I think IM should be consistent in what it puts there.

Code: Select all

"%IP%convert" ^
  -size 100x100 xc:Red -trim ^
  txt:
rem
rem Creates 1x1, transparent white

"%IP%convert" ^
  -size 100x100 xc:Red -trim ^
  zero.gif
"%IP%identify" zero.gif
rem
rem zero.gif is 1x1 transparent black
"%IP%identify" -verbose zero.gif

"%IP%convert" ^
  -size 100x100 xc:Red -trim ^
  zero.tiff
"%IP%identify" zero.tiff
rem
rem zero.tiff is 1x1 transparent white
"%IP%identify" -verbose zero.tiff

"%IP%convert" ^
  -size 100x100 xc:Red -trim ^
  zero.jpg
"%IP%identify" zero.jpg
rem
rem Creates 1x1 white (JPG doesn't support transparency, of course).
"%IP%identify" -verbose zero.jpg
snibgo's IM pages: im.snibgo.com
User avatar
glennrp
Posts: 1147
Joined: 2006-04-01T08:16:32-07:00
Location: Maryland 39.26.30N 76.16.01W

Re: unexpected error "convert: geometry does not contain ima

Post by glennrp »

snibgo wrote:I don't know what file formats support zero images. If a format mandates a minimum size 1x1, I think IM should be consistent in what it puts there.
PNG specifies a minimum image size of 1x1, but the oFFs chunk allows all of the pixels to be off the page/canvas/screen/whatever. "-repage" prevents the oFFs chunk from being written.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: unexpected error "convert: geometry does not contain ima

Post by anthony »

snibgo wrote:Sadly, no.

I think it should handle zero images, in the same way that arithmetic can handle zero numbers. I think I read that version 7 will be able to do so.
It isn't that simple. No image file format I know of allows a zero sized image.

Really a zero sized image is just non-sensical.

When this happens the 1x1 image, is fully-transparent, as is marked as being a 'NULL' image.

NOTE it is a warning, as it is NOT an error!

GIF animations often will throw up a null image. They are required to hold the timing and meta-data that the original 'frame' contained, but otherwise no-longer take part in the animation sequence. You do not want IM to error abort when this happens. -layers RemoveDups will generally remove Null images correctly for GIF animations.
Examples...
http://www.imagemagick.org/Usage/anim_mods/#crop

Null image handling, removal, and reporting (as in identify output) is an area that could use a little more work.

I have wanted to add a -layers 'RemoveNull' operator, but never got round to it.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: unexpected error "convert: geometry does not contain ima

Post by snibgo »

I have mostly retracted that statement. IM does handle zero-sized images.
anthony wrote:Really a zero sized image is just non-sensical.
Is it? No more so, I think, than a zero-length string in a program.
snibgo's IM pages: im.snibgo.com
Post Reply