Page 1 of 1

[SOLVED] How to extend image borders

Posted: 2018-08-05T13:59:26-07:00
by Lecram
Hey guys,

is it possible to extend the outermost pixels of an image the same way OpenGL's GL_CLAMP_TO_EDGE does it?

Image
(See https://solarianprogrammer.com/2013/05/ ... -textures/)

Re: How to extend image borders

Posted: 2018-08-05T15:26:07-07:00
by GeeMack
Lecram wrote: 2018-08-05T13:59:26-07:00is it possible to extend the outermost pixels of an image the same way OpenGL's GL_CLAMP_TO_EDGE does it?
The edges of an image may be extended like your example by using -distort SRT and -virtual-pixel edge. An example running IM7 from a Windows command line might look like this...

Code: Select all

magick input.png -set option:distort:viewport %[fx:w*2]x%[fx:h*2] ^
   -virtual-pixel edge -distort srt "0,0 1 0 %[fx:w/2],%[fx:h/2]" output.png
To ask a proper question on this forum you should always include the version of IM you're using and what platform or OS you're working on.

EDITED: Fixed punctuation in the command.

Re: How to extend image borders

Posted: 2018-08-05T23:33:16-07:00
by Lecram
Thank you very much! :)

My OS is Ubuntu 17.10 x64_64 4.13 and I'm using ImageMagick 6.9.7-4 Q16 x86_64 20170114.

Your solution worked for me right after I replaced the x with a comma in the SRT part. Here's the full command (linux terminal):

Code: Select all

#!/bin/bash

convert "in.png" \
  -set option:distort:viewport %[fx:w*2]x%[fx:h*2] \
  -virtual-pixel Edge \
  -distort SRT "0,0 1,1 0 %[fx:w/2],%[fx:h/2]" \
  "out.png"
Here's the relevant documentation for future reference:

Re: How to extend image borders

Posted: 2018-08-06T07:12:07-07:00
by GeeMack
Lecram wrote: 2018-08-05T23:33:16-07:00Your solution worked for me right after I replaced the x with a comma in the SRT part.
Yep, that was a mistake on my part. I've edited my post to fix it. Glad it worked for you.