Content-aware image extent?

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
User avatar
Marsu42
Posts: 75
Joined: 2014-06-12T03:17:45-07:00
Authentication code: 6789
Location: Berlin

Content-aware image extent?

Post by Marsu42 »

I'd like to add a alpha-masked border around my images, but without cutting too much into the original content.

The idea is to inconspicuously extent the outer content of the image to an added border - basically what you would do in Photoshop with extent canvas and context-sensitive fill. Of course an automated IM result isn't to be as good, but as there is only some content visible through the border it doesn't need to be.

Any hints on how to add a border region around this image that is filled with some extension of the content - or is this beyond IM?
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Content-aware image extent?

Post by snibgo »

How big do you want the border?

This Windows BAT script gives a border of 4 pixels. Vary the blur, if you want. I have made the border opaque, but I'm not sure if that's what you want.

Code: Select all

convert ^
  rose: ^
  ( +clone ^
    -bordercolor None -border 4 ^
    -blur 0x1 ^
    -alpha off ^
  ) ^
  +swap ^
  -gravity Center -composite ^
  out.png
snibgo's IM pages: im.snibgo.com
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Content-aware image extent?

Post by fmw42 »

see distort srt with viewport at http://www.imagemagick.org/Usage/distor ... t_viewport and set the virtual-pixel appropriately for extending the border. see http://www.imagemagick.org/script/comma ... tual-pixel

If on unix, see my script imageborder at the link below
User avatar
Marsu42
Posts: 75
Joined: 2014-06-12T03:17:45-07:00
Authentication code: 6789
Location: Berlin

Re: Content-aware image extent?

Post by Marsu42 »

fmw42 wrote:If on unix, see my script imageborder at the link below
Right, thanks, that's it! You can run *nix shell scripts on Windows through cygwin (or msys/mingw) bash just fine btw.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Content-aware image extent?

Post by fmw42 »

Marsu42 wrote:
fmw42 wrote:If on unix, see my script imageborder at the link below
Right, thanks, that's it! You can run *nix shell scripts on Windows through cygwin (or msys/mingw) bash just fine btw.

Yes, I know that. Usually I mention Linux, Mac OS or Window with Cygwin. Just got lazy this time above and so just said unix.
Post Reply