Center Image on Canvas
Center Image on Canvas
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.
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Center Image on Canvas
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?
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
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
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
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Center Image on Canvas
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/
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/
- anthony
- Posts: 8883
- Joined: 2004-05-31T19:27:03-07:00
- Authentication code: 8675308
- Location: Brisbane, Australia
Re: Center Image on Canvas
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)
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/
https://imagemagick.org/Usage/
Re: Center Image on Canvas
I am now have trouble placing other images. Here is the command I am using:
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.
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
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Center Image on Canvas
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.buntone wrote:I am now have trouble placing other images. Here is the command I am using: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.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
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
I figured it out and sorry for the confusion.
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Center Image on Canvas
buntone wrote:I figured it out and sorry for the confusion.
What was the problem?
Re: Center Image on Canvas
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?
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Center Image on Canvas
Verbose output of what?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?
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
What I mean does convert or anything print anything out ever unless it finds an error?
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Center Image on Canvas
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.
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.
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Center Image on Canvas
Only for certain operations, but try adding -verbose and that will print whatever is relevant even if no error.buntone wrote:What I mean does convert or anything print anything out ever unless it finds an error?