Help with background and centering

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
colorful
Posts: 6
Joined: 2020-03-04T11:55:05-07:00
Authentication code: 1152

Help with background and centering

Post by colorful »

convert -size 800x600 -background gray -gravity center -flatten in.png out.png

I am trying to create a 800x600 image. Background be gray. Paste in.png in the center.

What am I doing wrong?

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

Re: Help with background and centering

Post by fmw42 »

-flatten uses -page to do offset and does not respect -gravity. Use -compose over -composite. Also -background does not create the background image. Use xc: or canvas:

Code: Select all

convert -size 800x600 xc:gray in.png -gravity center -compose over -composite out.png
See

https://imagemagick.org/Usage/layers/
https://imagemagick.org/Usage/canvas/

User avatar
GeeMack
Posts: 757
Joined: 2015-12-01T22:09:46-07:00
Authentication code: 1151
Location: Central Illinois, USA

Re: Help with background and centering

Post by GeeMack »

colorful wrote:
2020-03-13T08:51:00-07:00
I am trying to create a 800x600 image. Background be gray. Paste in.png in the center.
You can create a gray canvas and composite your image onto it as fmw42 suggested. You can also use "-extent" to expand the canvas of the input image to your desired dimensions. Try this...

Code: Select all

convert in.png -background gray -gravity center -extent 800x600 out.png

Locked