Page 1 of 1

Resize and combine

Posted: 2019-02-25T03:03:57-07:00
by KKL
Hi!
I'd like to convert my images to squares with the same size.
I have a white (backgroud) square on which I'd like to place the actual image. It would be great if the background rectangle could be resized to match the MAX(width or height) of the actual picture.
Meta:
resize background-pic width and height to max (width(pic1),height(pic1)
place pic1 centered on resized background-pic
output to pic1_new
Is it possible with the command line tool?
Rgds
KKL

Re: Resize and combine

Posted: 2019-02-25T06:06:29-07:00
by snibgo
What version of IM, on what platform? I'll assume IM v7 on Windows BAT.

Code: Select all

magick ^
  in.png ^
  -set option:MYSIZE %%[fx:max(w,h)]x%%[fx:max(w,h)] ^
  -size %%[MYSIZE] xc:Blue ^
  +swap ^
  -gravity Center ^
  -compose Over -composite ^
  out.png
I've used Blue because it's easier to see than White.

Re: Resize and combine

Posted: 2019-02-25T06:19:38-07:00
by KKL
Hi!
Thank you for your reply.
I am using Win command line (dos window)

Re: Resize and combine

Posted: 2019-02-25T06:22:05-07:00
by KKL
WAU! It Works!!
Thak you so much!!!

Re: Resize and combine

Posted: 2019-02-25T08:01:14-07:00
by GeeMack
KKL wrote: 2019-02-25T03:03:57-07:00resize background-pic width and height to max (width(pic1),height(pic1)
place pic1 centered on resized background-pic
output to pic1_new
Check snibgo's suggestion for a simple way to composite your input image over a square background. Here's a way to use "-extent" to expand the background to a "max(w,h)" square and produce the same result...

Code: Select all

magick input.png -gravity center -background white -extent %[fx:max(w,h)]x%[fx:max(w,h)] result.png
If you're using it in a BAT script you'll need to make those single percent signs "%" on the FX expressions into doubles "%%".