Page 1 of 1

Adding a margin of repeated pixels around edges of image

Posted: 2019-03-22T11:46:24-07:00
by owntheweb
Hello ImageMagick gurus,
I'm preparing textures for a 3D model and need to add a margin of repeated pixels around the edges. This will prevent odd seams at the edges of my model UV maps, adding a bit of margin there as well.

The image is 4054 pixels wide/high and want to resize to 4096, with the edges filled in with the repeating pixels.

I think I found the key at:
http://www.imagemagick.org/discourse-se ... hp?t=34525

I'm just not quite sure how to apply that to my use case just yet. I'm guessing this would happen with a negative crop to add borders then a variation from the link above?

Thanks for taking a look in advance!

Re: Adding a margin of repeated pixels around edges of image

Posted: 2019-03-22T13:25:01-07:00
by GeeMack
owntheweb wrote: 2019-03-22T11:46:24-07:00The image is 4054 pixels wide/high and want to resize to 4096, with the edges filled in with the repeating pixels.

I think I found the key at:
http://www.imagemagick.org/discourse-se ... hp?t=34525

I'm just not quite sure how to apply that to my use case just yet. I'm guessing this would happen with a negative crop to add borders then a variation from the link above?

It's always more helpful if you provide the version of IM you're using and what platform or OS you're working on.

Assuming v7 since that's used in the linked example, a command like this should put any size image in the center of a 4096x4096 canvas, and fill any difference in dimensions by repeating the edge rows of pixels from the input image.

Code: Select all

magick input.png -set option:distort:viewport 4096x4096 ^
   -virtual-pixel edge -distort SRT "%[fx:w/2],%[fx:h/2] 1 0 2048,2048" output.png
That command is in Windows syntax. To use on a *nix shell you'll have to at least change the continued line caret "^" to a backslash "\".

Re: Adding a margin of repeated pixels around edges of image

Posted: 2019-03-22T18:23:57-07:00
by owntheweb
Hello GeeMack,
Thanks for your response! I actually just read another response asking for version and should have posted.

I'm using:
ImageMagick 6.9.7-4 Q16 x86_64 20170114

I'll give this a shot as early as tonight and will report. Thanks again!!

Re: Adding a margin of repeated pixels around edges of image

Posted: 2019-03-22T19:18:11-07:00
by fmw42
Since you are using IM 6, you will have to change "magick" to "convert" in GeeMack's solution.

Re: Adding a margin of repeated pixels around edges of image

Posted: 2019-03-24T21:13:13-07:00
by owntheweb
This worked wonders. Thank you!!! :D :D :D