Expanding an image to 1 of 3 possible dimension. How?

Here is my Problem:
I have a bunch of images where I want to extend the canvas size to either 1024x1024, 2048x2048 or 4096x4096.

Here is how I like it to go:

  • read image
  • look for largest width or height
  • automaticly decide which to use, 1024x1024, 2048x2048 or 4096x4096 (the best fit one)
  • expand_y / expand_x
  • save

If there is another method without expand_ that would be fine to, the important part for me is that expand has the “neumann boundary conditions” which just fills the rest of the canvas with “smeared” pixels.

resize probably:

$ gmic sp lena resize 1024,1024,1,100%,0,1,0.5,0.5