Erik wrote: ↑2018-03-23T02:31:53-07:00I'd like to set the gravity depending on the size of the image.
There are at least a couple approaches I can think of to easily create this effect, although not by using "-gravity" and "-extent".
One way would be to use conditional FX expressions to set the page geometry. That would let you use the input dimensions to calculate an output canvas size and the location of the input image within that canvas. Then you can use "-coalesce" to create the finished result.
Another method would be to set the output canvas size with "-set option:distort:viewport ..." and use "-distort affine ..." to adjust the position of the input image within that viewport. That can be done with conditional FX expressions, too.
I'd have to know if "size of the image" means aspect, total area, longest side, etc. I'd also want to know if you only want the image placed north or south, or if you need other gravity/direction adjustments according to some particular criteria. Give us a more detailed description of what sorts of conditions you want to test for and what results you'd like based on those conditions.