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.
User avatar
fmw42
Posts: 26250
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

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

Post by fmw42 »

Just out of curiosity, under what conditions would one want to use a zero sized image? What kind of operation would need that?

Right now one can use null: for a placeholder image in IM.

snibgo
Posts: 12863
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 »

Some operations might naturally result in a zero-size image. For example:

- trimming a constant-colour image (IM handles this well)
- cropping to 0x0+0+0 (IM does error abort)
- resizing to 0x0! (IM does error abort)
- SRT with scale 0 (IM does error abort)
- resize a 100x100 image to 0.4% (IM does error abort)

If I am creating a picture-in-picture video effect, I might want to shrink an image away to nothing, each time compositing over some backdrop. IM could do that with "-resize", but it won't. When the image should be smaller than 0.5x0.5 pixels, it bombs out. SRT works correctly with very small values of scale, but for no reason that I can think of, it won't accept a zero scale.
snibgo's IM pages: im.snibgo.com

snibgo
Posts: 12863
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 »

Oh, yes, and

Code: Select all

convert -size 0x0 xc:Red r.png
gives me a 1x1 image that is red. Why doesn't it give the same result as

Code: Select all

convert -size 100x100 xc:Red -trim r.png
? No reason that I can think of.
snibgo's IM pages: im.snibgo.com

User avatar
fmw42
Posts: 26250
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

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

Post by fmw42 »

With respect to resizing and possibly other things, one certainly can do computations before hand and then either do or skip the operation if it leads to too small or zero sized images.

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 »

cropping with 0x0 means crop using the virtual canvas size!
With 0x0+0+0 it means crop image to the virtual canvas!

Generally that does not produce a 0 sized image, but as with any crop, it can. It may even generate a resulting image with non-zero virtual offset.

NOTE The actual image may not be fully contained by its virtual canvas, a fact used in some GIF animations (and which IE 8 has problems with). It can have an offset that places it beyond the bounds (positive or negative) of the virtual canvas (which is always a positive size starting at origin).

Actually such a crop would be useful in GIF animations!
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/

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:Oh, yes, and

Code: Select all

convert -size 0x0 xc:Red r.png
gives me a 1x1 image that is red. Why doesn't it give the same result as

Code: Select all

convert -size 100x100 xc:Red -trim r.png
? No reason that I can think of.
-size 0x0 means Default size which for a canvas (xc:) means a 1x1 single pixel image. For labels it means fit the image size to text bounds.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/

IvanUrwin
Posts: 4
Joined: 2020-01-29T02:40:02-07:00
Authentication code: 1152

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

Post by IvanUrwin »

I have found this thread from a search on convert.exe: geometry does not contain image

The error occurred running a script which was producing a pyramid of tiles from a large image. First one 256x256 thumbnail image of the whole 16384x16384 picture, then halving the original image horizontally and verticall producing four 256x256 tiles from the 8192x8192 quarters, then 16 4192x4192 images turned into 16 smaller (256x256) tiles etc.

The script was in tcl and ran fine with three nested loops running through the pyramid level, X and Y.

All ran fine until the start of the last pyramid slice, extracting the first corner of the bottom layer.
That should have extracted a 256x256 square from the original image into a 256x256 tile.

Code: Select all

exec $convert $source -crop ${inputTileSize}x${inputTileSize}+${XStart}+${YStart} -geometry ${outputTileSize}x${outputTileSize} $tilename
This would have given an OS command something like

Code: Select all

convert.exe LargeCrop.png -crop 256x256+0+0 -geometry 256x256 L6X0Y0.jpg
although the real command had a full path to the .EXE file etc.

I am guessing that some software in Imagemagick has an incorrect comparison e.g. LESS THAN instead of LESS THAN OR EQUALS that is preventing tis from running. Normally, why would anyone want to specify a geometry 256x256 on an image that is already 256x256? Here, its happening because its in a script where ${inputTileSize} and ${outputTileSize} are different for all the other layers.

I'm adding this below as it probaby indicates the version of Magick I was running

Code: Select all

set ImageMagick {C:\Program Files\ImageMagick-6.9.10-Q16-HDRI}
set convert "${ImageMagick}/convert.exe"
The error message (copy-pasted) :-

Code: Select all

convert.exe: geometry does not contain image `LargeCrop.png' @ warning/transform.c/CropImage/667.
In an attempt to understand what is going on, I removed the geometry specification for the last layer of my pyramid and the problem still occurs.

I then tried starting my X and Y loops at 1 instead of zero to see if that makes a difference and the script is now running. These have worked okay ...

Code: Select all

C:\Program Files\ImageMagick-6.9.10-Q16-HDRI/convert.exe LargeCrop.png -crop 256x256+256+256 L6X1Y1.jpg
C:\Program Files\ImageMagick-6.9.10-Q16-HDRI/convert.exe LargeCrop.png -crop 256x256+256+512 L6X1Y2.jpg
C:\Program Files\ImageMagick-6.9.10-Q16-HDRI/convert.exe LargeCrop.png -crop 256x256+256+768 L6X1Y3.jpg
so the problem appears to be related to the +0+0 part of the cropping.

User avatar
fmw42
Posts: 26250
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

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

Post by fmw42 »

Can you provide a link to your LargeCrop.png image? Perhaps it has a virtual canvas with offsets that are causing the issue. Did you do +repage after your crops at the levels above?

By the way, I do not understand your purpose for adding -geometry? If you want to be sure the tile is filled out with padding, use -extent.

IvanUrwin
Posts: 4
Joined: 2020-01-29T02:40:02-07:00
Authentication code: 1152

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

Post by IvanUrwin »

Purpose of adding -geometry
========================
(irrelevant to the problem. ignore?)

Layer 0 of my pyramid of tiles is -crop 16384x16384+0+0 to -geometry 256x256 to create a tile with an overview image

Layer 1 is crop 8192x8192+(some X)+(some Y) to -geometry 256x256 to create 4 tiles representing a quarter of the image each (TL, TR, BL, BR)
Layer 2 crops 4094x4094 squares to create 16 tiles 256x256. e.g. the yellow 1/16th in the top right corner with the fine lines
...
Layer 6 - the last - crops 256x256 (dimension) squares to give 64x64=4096 (number) tiles of dimension 256x256, eg this

So the -geometry part is in the script because it rescales all the large images down to 256x256.
For the last layer, the images are already 256x256 but the script didn't treat it as a special case, assuming Imagemagick would run okay.

+repage
=======
I did not try that. I will look into what it does and why I might need it.

LargeCrop.png
============
I've taken out a temporary DNS name where you can see the file
http://lig-nanowise.ddns.net/LargeCrop.png

I am testing to see whether I can use OpenSeaDragon to host images.
http://lig-nanowise.ddns.net

You should see a broken oil stained bit of a silicon chip photographed on a microscope with a 5x lens and cropped down to about 1/4 of a gigapixel as a test. If I get things working well, my plan might be to photograph a larger area using a nanoscope and 230x lens so that you can zoom from say a 4cm square overview to see details a fraction of a micron in size.

Back to the problem
=================

Code: Select all

"C:\Program Files\ImageMagick-6.9.10-Q16-HDRI/convert.exe" LargeCrop.png -crop 256x256+0+0 L6X0Y0.jpg
was giving

Code: Select all

convert: geometry does not contain image

Code: Select all

"C:\Program Files\ImageMagick-6.9.10-Q16-HDRI/convert.exe" LargeCrop.png -crop 256x256+0+256 L6X0Y1.jpg
convert.exe: geometry does not contain image `LargeCrop.png' @ warning/transform.c/CropImage/667.
From this, I assume that the root cause of the problem is with X=0 since the problem occurs in the example above too.

User avatar
fmw42
Posts: 26250
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

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

Post by fmw42 »

Your syntax does not make sense to me. If you add offsets to -crop, then it will only make one output. -geometry should not generally be used for resizing. Use -resize. For example:

Code: Select all

convert lena.jpg -crop 200x200+0+0 -geometry 100x100 lena_crop.png
Where lena.jpg is 256x256 and the result is only one 100x100 image, not 4. You should use

Code: Select all

convert lena.jpg -crop 200x200 -resize 100x100 lena_crop.jpg
If you want to pad it out, then add -exent 100x100.

By leaving off the +X+Y, -crop will crop as many sections as it needs to tile out the image. If you save as PNG, the offsets are stored in the files and so you can just use -layers merge to put the image back again. See https://imagemagick.org/Usage/crop/#crop_tile

Code: Select all

convert lena.jpg -crop 200x200 -resize 100x100 -extent 100x100 lena_crop.png
Without the +repage, each png quadrant will store its positional offsets (that could mess up your next layer crops). With +repage, each quadrant has +0+0 offsets.

JPG does not save offsets (where PNG does). So no +repage would be needed.
For the last layer, the images are already 256x256 but the script didn't treat it as a special case, assuming Imagemagick would run okay.
That is a bad assumption. ImageMagick will not know that you are at your desired size already and will try to process it.

However, this does work:

Code: Select all

convert lena.jpg -crop 256x256 -geometry 256x256 x.png
And makes only one image of size 256x256.

But I am still confused. Do you use -geometry 256x256 for every level including the last? What is the command for the last layer and the input size that you use? Please provide the command and input such that I can check your image and run the command that fails for you.

IvanUrwin
Posts: 4
Joined: 2020-01-29T02:40:02-07:00
Authentication code: 1152

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

Post by IvanUrwin »

Your syntax does not make sense to me. If you add offsets to -crop, then it will only make one output. -geometry should not generally be used for resizing. Use -resize.

I will use -resize in future. I don't use IM on a regular basis and there are so many options that the correct ones don't always stand out to me. Because the commands did what I wanted for the other layers and offsets I assumed the command would work for X=0 with a 256x256 input area (after the cropping).

Yes, my `-crop` was only intended to create one output tile because I wasn't aware I could create a set of tiles with a single command. Hence I had three nested loops in a script (layer, X and Y), creating 1 tile in layer 0, then (number) 2x2=4 tiles in layer 1, then 4x4=16 tiles in layer 2, up to 64x64 tiles in layer 6.

Without the +repage, each png quadrant will store its positional offsets (that could mess up your next layer crops). With +repage, each quadrant has +0+0 offsets.


Thanks for the explanation of `+repage`, I have seen it used on a number of occasions but not understood what it did.

Back to the problem
==================

This command won't run...

Code: Select all

"C:\Program Files\ImageMagick-6.9.10-Q16-HDRI/convert.exe" LargeCrop.png -crop 256x256+0+0 L6X0Y0.jpg
I've taken out a temporary DNS name where you can see the source image file
http://lig-nanowise.ddns.net/LargeCrop.png

This is the error message I am getting

Code: Select all

convert.exe: geometry does not contain image `LargeCrop.png' @ warning/transform.c/CropImage/667.
The problem is with the X offset of zero. Y offsets of zero are okay.
You can see that the problem is not related to `-geometry` or `-resize` as I removed any resizing. The last layer doesn't require it and I am just trying to get to the root of the problem.

In future
========

Code: Select all

By leaving off the +X+Y, -crop will crop as many sections as it needs to tile out the image.
If that works then I will forget about `-crop 256x256+0+0` not working (for me with the large file).
Letting IM manage the tile creation is what I should have done in the first place. It is surely much faster. Clearer software, etc.

You have been a great help Fred, not just in replying to my questions, but in what I have learnt from your replies to others.
It's much appreciated.

snibgo
Posts: 12863
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

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

Post by snibgo »

IvanUrwin wrote:I've taken out a temporary DNS name where you can see the source image file
http://lig-nanowise.ddns.net/LargeCrop.png
The file is 372MB, too large for me to download. Perhaps it already has a canvas offset, so there are no pixels at (0,0) in the canvas. What does "convert LargeCrop.png -verbose info:" say?

If it does have a canvas offset, you can remove it by doing "+repage" immediately after reading the file.
snibgo's IM pages: im.snibgo.com

User avatar
fmw42
Posts: 26250
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

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

Post by fmw42 »

Just provide the last layer image and the command where it fails, not your full large image. It is possible your large image is too large for your system and/or ImageMagick policy.xml file resources.

IvanUrwin
Posts: 4
Joined: 2020-01-29T02:40:02-07:00
Authentication code: 1152

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

Post by IvanUrwin »

Perhaps it already has a canvas offset, so there are no pixels at (0,0) in the canvas.

I'm really sorry you guys had to spend time on this. I have learnt a fair bit in the process.

I think that's it. When I decided to work with powers of two to keep things simple for my test image, I cropped the micrscope image down from its original size to create my LargeCrop.png 16384x16384 and shaved a bit off the left hand side of the image in the process, unaware of all this canvas stuff.

I believed I had a simple 16384x16384 image.

I think I have learnt the very hard way what `+repage` does, and should have used that option when cropping the image from my microscope down to a nice power of two in size (2^14=16384), and before using it.

Many thanks. I am relieved now.

Post Reply