[SOLVED] How to extend image borders

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
Lecram
Posts: 13
Joined: 2018-07-28T12:00:45-07:00
Authentication code: 1152
Location: Germany

[SOLVED] How to extend image borders

Post 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/)
Last edited by Lecram on 2018-08-05T23:33:30-07:00, edited 1 time in total.
User avatar
GeeMack
Posts: 718
Joined: 2015-12-01T22:09:46-07:00
Authentication code: 1151
Location: Central Illinois, USA

Re: How to extend image borders

Post 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.
Last edited by GeeMack on 2018-08-06T07:11:08-07:00, edited 1 time in total.
Lecram
Posts: 13
Joined: 2018-07-28T12:00:45-07:00
Authentication code: 1152
Location: Germany

Re: How to extend image borders

Post 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:
User avatar
GeeMack
Posts: 718
Joined: 2015-12-01T22:09:46-07:00
Authentication code: 1151
Location: Central Illinois, USA

Re: How to extend image borders

Post 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.
Post Reply