Imagemagick inline border without resizing the original image - image-processing

I tried to add a border to an image of dimension 200x200 px using the below code.
convert -border 2x2 -bordercolor "#cccccc" old.png new.png
The above code ads a 2 px border around the old.png. Therefore, the image expands to 204x204 px.
However, I want to add an inline border. I have no issues with border overlaying edge portions of the old image. Thus, the new image should be able to retain the dimensions 200x200 px. Please advise how exactly to do that.

You need to shave two pixels all around and then add a two pixel border. You should try this with Imagemagick 6. If using Imagemagick 7, replace convert with magick.
convert old.png -shave 2x2 -bordercolor "#cccccc" -border 2 new.png

Related

How to remove alpha channeled margins from an image using ImageMagick

I have an image that all four margins are transparent alpha channels and I want to crop all margins and only keep the non-alpha channel parts. Is there any way to do it with ImageMagick? Take this image as an example but consider its transparent margins!
You can do that in Imagemagick using -trim to automatically remove the constant transparent regions.
convert img.png -trim +repage result.png

Cropping a variable width frame with graphicsmagick

I have some images that have a transparent border of varying width; I'd like to crop these to the visible parts of image. (I imagine a solution won't be specific to the transparent part, but would work with a frame of any color.)
E.g. the 200x200 image below has a transparent border of 3 pixels. I'd like to get the equivalent of
$ gm convert a.png -crop 194x194+3+3 b.png
without having to determine the numbers by hand. Is this possible with graphicsmagick (or imagemagick)?

How to add a white space around an image using online tools like Pixlr Editor or imagemagick ?

I want to put some white space around an image in equal length. I want to maintain the image pixel ratio to 12:7 too. Any help would do a great help. Thank you.
Another method using Imagemagick V7:
magick ShF4m.jpg -background white -gravity center -extent "%[fx:w+20]"x"%[fx:h+20]" result.jpg
Open image, set the background to white, set the gravity to the centre so the -extent extends the canvas in all directions, increase the canvas size by 20px on the width and 20px on the height.
It would be simple in ImageMagick if you wrote over the inside of the border with white. That way you do not change the image dimensions nor aspect ratio. Here I shave 10 pixels all around and then put a 10 pixel white border all around. Here I will add a red border just to make it visible. But you can change red to white later.
convert barn.jpg -shave 10x10 -bordercolor red -border 10x10 barn_border10.jpg
It would be very hard to add white outside the image of equal amount and keep the aspect ratio. I do not think you can have equal white border amounts and keep the aspect ratio.

Imagemagick Crop image borders for lot of images with different sizes

I have a lot of images. Size of images are different.
I need to write the one imagemagick commandline operation to crop the borders of each image (for example, 10px of each edge).
Basic usage of -crop reuire to know the image geometry - it's not usefull.
Use -shave
convert montage.png -shave 10x10 montage.png

ImageMagick: placing a frame along the edges of an image

What is the most efficient, idiomatic way with ImageMagick to turn this:
Into this:
Please note: canvas size remains unchanged, a frame of arbitrary color and width is applied "on top" of the original image.
I think I would just shave 30 pixels off then add 30 pixels of border back on:
convert rose.jpg -shave 30 -bordercolor cyan -border 30 result.png
I'll let you do the colour-matching ;-)

Resources