Center Image on Canvas

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
buntone
Posts: 8
Joined: 2011-07-29T08:23:41-07:00
Authentication code: 8675308

Center Image on Canvas

Post by buntone »

I have images that are variable widths but always the same height. I have a canvas that is smaller than the width of the image that is being placed on it. How would I format the command so that the image is centered at the top of the canvas.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Center Image on Canvas

Post by fmw42 »

It might be best to provide links to your images. But as a guess, see -gravity north and -compose ... -composite.

http://www.imagemagick.org/Usage/layers/#convert
http://www.imagemagick.org/Usage/compose/

Also what version of IM are you using and on what platform?
buntone
Posts: 8
Joined: 2011-07-29T08:23:41-07:00
Authentication code: 8675308

Re: Center Image on Canvas

Post by buntone »

Here are the images: http://imgur.com/a/R3GcJ

the cover-image.jpg is first resized to respect aspect ratio and give it a height of 1950 and also converted to CMYK.

Version: 6.5.7-8 Platform: Linux
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Center Image on Canvas

Post by fmw42 »

Your images got convert to sRGB jpgs, so I am not sure about the CMYK. It is usually better to convert to CMYK last as some IM processes do not work in CMYK colorspace such as -resize.

Anyway, there are two ways to approach this.

One way is to ignore your canvas image and just expand your image with white background using -extent, since you know how tall and wide you want the canvas to be.

convert rW7Y2h.jpg -resize 779x -background white -gravity north -extent 779x1024 rW7Y2h_ext.jpg

The otherway is just to resize and overlay

convert WbndPh.png.jpeg \( rW7Y2h.jpg -resize 779x \) -gravity north -compose over -composite rW7Y2h_comp.jpg

see
http://www.imagemagick.org/Usage/resize/
http://www.imagemagick.org/script/comma ... p#geometry
http://www.imagemagick.org/Usage/resize/#space_fill
http://www.imagemagick.org/Usage/crop/#extent
http://www.imagemagick.org/Usage/layers/#convert
http://www.imagemagick.org/Usage/compose/
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Center Image on Canvas

Post by anthony »

The best guide is 'padding' in thumbnails
http://www.imagemagick.org/Usage/thumbnails/#pad

The space-fill guide is for much older IM's before the '^' resize flag was added. (before version 6.3.8-3 - that is a very long time ago)
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
buntone
Posts: 8
Joined: 2011-07-29T08:23:41-07:00
Authentication code: 8675308

Re: Center Image on Canvas

Post by buntone »

I am now have trouble placing other images. Here is the command I am using:

Code: Select all

convert cover-image.jpg -density 300x300 -resize x1950 -background white -gravity north -extent 2269x2952  -page +0+2575 accentStripe.tiff -page +0+2430 miniStripe.tiff -page +25+2575 authorText.tiff -page +75+1966 bookTitle.tiff -flatten  test.jpg
Here are the remaining images: http://imgur.com/a/B9A9o. The problem I am having is that only the miniStripe shows up. Thanks for all the help.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Center Image on Canvas

Post by fmw42 »

buntone wrote:I am now have trouble placing other images. Here is the command I am using:

Code: Select all

convert cover-image.jpg -density 300x300 -resize x1950 -background white -gravity north -extent 2269x2952  -page +0+2575 accentStripe.tiff -page +0+2430 miniStripe.tiff -page +25+2575 authorText.tiff -page +75+1966 bookTitle.tiff -flatten  test.jpg
Here are the remaining images: http://imgur.com/a/B9A9o. The problem I am having is that only the miniStripe shows up. Thanks for all the help.
I cannot correlate the images at your link with the filenames you use and the one text image looks cut off. Also I am having trouble understanding what exactly you want to do. Can you provide the images with the proper names? Or change your code to show the names of the uploaded files? Your images have had their names changed and converted to jpg. Perhaps you need to find some other image hosting site that will not convert your images to jpg and rename them. Or explain how to get your proper images downloaded from this site.

On the surface, I do not see anything obviously wrong with your command. But I really do not know what to expect until I see the actual images and know what you expect the result to look like.
buntone
Posts: 8
Joined: 2011-07-29T08:23:41-07:00
Authentication code: 8675308

Re: Center Image on Canvas

Post by buntone »

I figured it out and sorry for the confusion.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Center Image on Canvas

Post by fmw42 »

buntone wrote:I figured it out and sorry for the confusion.

What was the problem?
buntone
Posts: 8
Joined: 2011-07-29T08:23:41-07:00
Authentication code: 8675308

Re: Center Image on Canvas

Post by buntone »

I don't really know, I just broke it up into two commands one doing the extent and the other putting the images on the result of the extent. More of a work around. Is there a way to get a verbose output?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Center Image on Canvas

Post by fmw42 »

buntone wrote:I don't really know, I just broke it up into two commands one doing the extent and the other putting the images on the result of the extent. More of a work around. Is there a way to get a verbose output?
Verbose output of what?

try this

convert cover-image.jpg -density 300x300 -resize x1950 -background white -gravity north -extent 2269x2952 +repage -page +0+2575 accentStripe.tiff -page +0+2430 miniStripe.tiff -page +25+2575 authorText.tiff -page +75+1966 bookTitle.tiff -flatten test.jpg

or

convert -respect-parenthesis \( cover-image.jpg -density 300x300 -resize x1950 -background white -gravity north -extent 2269x2952 +repage \) -page +0+2575 accentStripe.tiff -page +0+2430 miniStripe.tiff -page +25+2575 authorText.tiff -page +75+1966 bookTitle.tiff -flatten test.jpg
buntone
Posts: 8
Joined: 2011-07-29T08:23:41-07:00
Authentication code: 8675308

Re: Center Image on Canvas

Post by buntone »

What I mean does convert or anything print anything out ever unless it finds an error?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Center Image on Canvas

Post by fmw42 »

You can try adding -verbose or -debug to your command but I don't know if that will help. See http://www.imagemagick.org/Usage/basics/#controls

What I do to test commands it put in -write tmpX.png after each operation, but in your command there are only a few places; after the -resize, after the -extent and then at the end.

Note that -page ... -flatten is not -gravity sensitive. However, you can chain -gravity ... -geometry ... -composites in pairs, since -geometry ... -composite are gravity sensitive.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Center Image on Canvas

Post by fmw42 »

buntone wrote:What I mean does convert or anything print anything out ever unless it finds an error?
Only for certain operations, but try adding -verbose and that will print whatever is relevant even if no error.
Post Reply