border color

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
mathfeel

border color

Post by mathfeel »

Hi,

I am writing a script to pad the file I have with a border so that the final size is close to a square. I would like to be able to sample a pixel on the border (edge pixel?) of the existing file and use that as argument to -bordercolor. Reading through the documentation, I did not find anything about how to do such sampling. Anyone?

Thanks,

--Z
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: border color

Post by fmw42 »

You need to do that in two command lines. First command line to get the color and save as a variable. Second command line to use the variable for your bordercolor.

color=`convert image -format "%[pixel:s.p{X,Y}]" info:`
convert image -bordercolor $color -border XX,YY resultimage

X,Y is the pixel location to sample to get the color

XX,YY is the pad in X and Y direction

see FX escapes at http://www.imagemagick.org/Usage/transform/#fx_escapes

see -border at http://www.imagemagick.org/Usage/crop/#border
Post Reply