Batch resizing of canvas centering the images

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?".
Locked
elbarto
Posts: 8
Joined: 2020-03-26T02:58:23-07:00
Authentication code: 1152

Batch resizing of canvas centering the images

Post by elbarto »

Hello, I am new to ImageMagick,

I am using ImageMagick in Debian.

I need to increase the canvas of a couple of hundreds pictures, I want to preserve the ratio and increase the canvas all around the pictures of a 10% and center the image in the canvas.

Like in this example:

Image
Image

Here the canvas is light gray, but I would prefer to have it transparent or white since this is the background of the images.

I am totally new at this so any help will be appreciated.

Cheers.
_just_think_positive_my_dear_

snibgo
Posts: 13034
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Batch resizing of canvas centering the images

Post by snibgo »

Code: Select all

magick in.png -gravity center -background None -extent 110x110% out.png
You can use any background colour you want.
snibgo's IM pages: im.snibgo.com

elbarto
Posts: 8
Joined: 2020-03-26T02:58:23-07:00
Authentication code: 1152

Re: Batch resizing of canvas centering the images

Post by elbarto »

snibgo thanks.

magick is not installed on the current version of imagemagick I have
Last edited by elbarto on 2020-03-26T12:18:21-07:00, edited 2 times in total.
_just_think_positive_my_dear_

snibgo
Posts: 13034
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Batch resizing of canvas centering the images

Post by snibgo »

What version of IM do you have? If v6, use "convert" instead of "magick".
snibgo's IM pages: im.snibgo.com

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

Re: Batch resizing of canvas centering the images

Post by fmw42 »

How did you do the install? It should be installed already on Linux. You just need to find it.

elbarto
Posts: 8
Joined: 2020-03-26T02:58:23-07:00
Authentication code: 1152

Re: Batch resizing of canvas centering the images

Post by elbarto »

snibgo wrote:
2020-03-26T11:46:39-07:00
What version of IM do you have? If v6, use "convert" instead of "magick".
I installed from source the latest version and now it worked! On Trisquel

super happy :D

I suppose I just have to use the *.png instead of in.png

like this:

Code: Select all

magick in.png -gravity center -background None -extent 110x110% out.png
_just_think_positive_my_dear_

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

Re: Batch resizing of canvas centering the images

Post by fmw42 »

If you are trying to process many images, then use mogrify to process all images in a folder. If on IM 7, then it would be magick mogrify.

elbarto
Posts: 8
Joined: 2020-03-26T02:58:23-07:00
Authentication code: 1152

Re: Batch resizing of canvas centering the images

Post by elbarto »

yes I am trying to do multiple images on IM7, so this should be the code:

Code: Select all

magick mogrify *.png -gravity center -background None -extent 110x110% *.png
it will overwrite the images, at least it did now when I tried.

-path does not work for me for selecting an output folder

edit: thanks fmw42!!! :) help really appreaciated!
_just_think_positive_my_dear_

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

Re: Batch resizing of canvas centering the images

Post by fmw42 »

The *.png should only be at the end. That is where the input goes. To direct this to some other locations so that it does not overwrite your files, create a new empty directory and use the -path argument to specify its location. The folder has to exists already before mogrify will place it there with -path.

Code: Select all

magick mogrify -path path_to_existing_empty_directory -gravity center -background None -extent 110x110% *.png

elbarto
Posts: 8
Joined: 2020-03-26T02:58:23-07:00
Authentication code: 1152

Re: Batch resizing of canvas centering the images

Post by elbarto »

thanks it worked perfectly!

I'll made a donation to the project! Even if what I am doing is for personal use I will save tons of time with ImageMagick, thanks to all of you! :)
_just_think_positive_my_dear_

Locked