Page 1 of 1

Center Image on Canvas

Posted: 2012-06-14T13:05:30-07:00
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.

Re: Center Image on Canvas

Posted: 2012-06-14T13:21:06-07:00
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?

Re: Center Image on Canvas

Posted: 2012-06-14T13:40:30-07:00
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

Re: Center Image on Canvas

Posted: 2012-06-14T14:22:25-07:00
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/

Re: Center Image on Canvas

Posted: 2012-06-14T16:26:07-07:00
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)

Re: Center Image on Canvas

Posted: 2012-06-15T05:24:22-07:00
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.

Re: Center Image on Canvas

Posted: 2012-06-15T09:52:49-07:00
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.

Re: Center Image on Canvas

Posted: 2012-06-15T10:07:16-07:00
by buntone
I figured it out and sorry for the confusion.

Re: Center Image on Canvas

Posted: 2012-06-15T10:12:21-07:00
by fmw42
buntone wrote:I figured it out and sorry for the confusion.

What was the problem?

Re: Center Image on Canvas

Posted: 2012-06-15T10:17:36-07:00
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?

Re: Center Image on Canvas

Posted: 2012-06-15T10:20:57-07:00
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

Re: Center Image on Canvas

Posted: 2012-06-15T10:24:53-07:00
by buntone
What I mean does convert or anything print anything out ever unless it finds an error?

Re: Center Image on Canvas

Posted: 2012-06-15T10:27:48-07:00
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.

Re: Center Image on Canvas

Posted: 2012-06-15T10:28:48-07:00
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.