0

I am starting with a rectangular picture of size say 700x700. I wish to extend it to 1000x1000, with the picture centered, and the outermost 1 pixel completely black (say). The space between the centered picture and the 1 pixel border should be extrapolated as a gradient from the picture to black:

extrapolate

Can GIMP do that?

2 Answers 2

1

Yes, but it's quite complicate and fiddly...

You can extend indefinitely the image with a "displace map". A displace map tells a pixel where its new value comes from. The map (from 0% to 100%, but this is rescaled to -100%, +100%) is a coefficient applied to a global displacement. So for instance if the global displacement is 100px and map is 50% gray under the pixel, the pixel doesn't change it is replace by the same pixel). If the map is 75% gray (so this is rescaled to +50%) the pixel is replaced by the pixel 50px on its right, and if the map is black (0%, rescaled to -100%) the pixel is replaced by the pixels 100px on its left. Now, if the map is a linear gradient, from 50% gray to black going to the right, and if the displacement is the width of the gradient, then

  • the pixel on left, over gray, doesn't change,
  • the pixel at the end of the gradient, seeing black copies the pixel which is the displacement on its left, and this is the pixel on the left end,
  • and similarly any intermediate pixel copies the pixel which is displacement * map value on the left, which is also the pixel on the left end

... so in effect you spread the leftmost pixel over the whole gradient.

With this is mind we can make up X and Y displace maps to stretch the edges:

enter image description here

Note that:

  • I cheat a bit, the map gradient doesn't start on the last pixel of the image, but on the first outside of it, which is why the gradients doesn't start on 50% gray.
  • The image must be in high precision mode (32-bit FP).In 8 bit th gradient is not accurate enough and you get artifacts
  • For the same reason, disable dithering and supersampling in the gradient tool.

You can then apply the tow displace map using Filters > Map > Displace. When the displacement in the dialog gets close to the with of the gradients, the image spreads out.

So starting with this:

enter image description here

And applying this:

enter image description here

We obtain this:

enter image description here

If you managed to do this, the rest is a trivial layer mask over a black background:

enter image description here

enter image description here

Remember that you can apply color tools to the mask to alter the opacity change, for instance just by playing with the middle handle in Levels:

enter image description here

You change to this:

enter image description here

1

The question is related to GIMP, but there is a perhaps more affordable solution with ImageMagick.

Assuming that your starting image is 300x300px and you want a final image of 500x500px (like in your example), you can use distort and blur options...

magick.exe convert "original_image.png" \
  -set option:distort:viewport %[fx:500]x%[fx:500] \
  -virtual-pixel Edge -distort SRT "0,0 1,1 0 %[fx:100],%[fx:100]" \
  -write mpr:img0 -evaluate set 100% -bordercolor black -shave 50 -border 50 \
  -blur 60x100 mpr:img0 -compose multiply -composite \
  "output image.png"

...to obtain the following result:

processed image

You can tweak the parameters until you are satisfied with the result.

For the example I've used the Windows version of ImageMagick, but the syntax is the same for other Operating Systems.

Note: there is also a script on Fred's ImageMagick Scripts website. It seems to be simple to use, but I haven't tried it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.