Uneven border

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
Zippo25

Uneven border

Post by Zippo25 »

I'm looking for a simple Polaroid like picture effect... This would be taking the original image, and putting a white border around it outlined with a thin black line with more space at the bottom of the image to place a caption and other info.

The following command line, creates a nice simple photo look with an even border around it:

Code: Select all

convert input.jpg -bordercolor white -border 10x10 -bordercolor black -border 1x1 output.jpg
Example:

Image

Changing this to increase the y of the white border to give more space:

Code: Select all

convert input.jpg -bordercolor white -border 10x30 -bordercolor black -border 1x1 output.jpg
Adds more space top to bottom, but the image is centered top to bottom as well which is not what I am looking for.

Example:
Image

Is there a way to offset the image so that it is not centered top to bottom but rather has more space on the bottom?

Example:

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

Re: Uneven border

Post by fmw42 »

see -extent http://www.imagemagick.org/Usage/crop/#extent

Do -border followed by -extent


You can also use -splice.

Or you can create a white image of the excess size you want and -append it at the bottom.
http://www.imagemagick.org/script/comma ... php#append
Zippo25

Re: Uneven border

Post by Zippo25 »

Hmmm ...

1) don't know the size of the image before hand... Can use identify to figure that out and then generate the output..

2) Version of ImageMagick is old enough to not have that command (-extent)... Not sure if I can get it upgraded.

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

Re: Uneven border

Post by fmw42 »

you can also create the output the size you want as a white background and overlay your image onto it at the top so that the excess white remains below.

consider 20 pixel border all around and another 50 pixels of white at the bottom:


Get the width and height using IM and add your border all using IM fx calculations and strings

convert <image> -bordercolor white -border 20 <tmpimage>
width=`convert <tmpimage> -format %w info:`
height=`convert <tmpimage> -format %h info:`
convert <tmpimage> \( -size ${width}x50 xc:white \) -append <newimage>

or

width=`convert <image> -format %w info:`
height=`convert <image> -format %h info:`
width2=`convert xc: -format "%[fx:$width+40]" info:`
height2=convert xc: -format "%[fx:$height+40+50]" info:`
convert \( -size ${width2}x${height2} xc:white \) \( <image> -bordercolor white -border 20 \) \
-gravity north -composite <newimage>

or

width=`convert <image> -format %w info:`
height=`convert <image> -format %h info:`
width2=`convert xc: -format "%[fx:$width+40]" info:`
height2=convert xc: -format "%[fx:$height+40+50]" info:`
convert \( -size ${width2}x${height2} xc:white \) <image> \
-geometry ${width2}x${height2}+20+20 -composite <newimage>
Zippo25

Re: Uneven border

Post by Zippo25 »

Cool... will give that a try. Of the 22 servers checked, 12 had older versions... weird.
Zippo25

Re: Uneven border

Post by Zippo25 »

This worked...

Code: Select all

convert source.jpg -bordercolor white -border 10x10 temp1.jpg
width=`identify temp1.jpg -format %w`
height=`identify temp1.jpg -format %h`
convert temp1.jpg -size ${width}x35 xc:white -append temp2.jpg
convert temp2.jpg -bordercolor black -border 1x1 output.jpg
Example:

Image

Thanks for pointing me in the right direction....
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: Uneven border

Post by Bonzo »

There is a poleroid method in later versions of ImageMagick: http://redux.imagemagick.org/script/com ... p#polaroid

Out of interest this is a method to make a row of images and in this case I am using php to also generate a type of "imagemap".
http://www.rubblewebs.co.uk/imagemagick ... _f_74.html
It is based on an example written by Anthony.
Post Reply