Page 1 of 1

How to "center center" an image

Posted: 2013-01-30T09:23:15-07:00
by ultranerds
Hi,

I'm trying to thumbnail my images so they always make 300x300px, but are centered bother horizontally AND vertically. For the design of my site (in rows) I need to keep all the images the same size.

I've tried:

convert -define jpeg:size=200x200 7UFFBJ7XVryG2hEljnQH247FObz9Kl.jpg -thumbnail 200x200^ -gravity center -extent 200x200 test-7UFFBJ7XVryG2hEljnQH247FObz9Kl.jpg

..and this does make the thumb ok, but its only centered at the top of the image. The following shows an example of what I'm currently getting, and what I want:

http://mywebsitedesignersblog.com/what-i-want.png

Any ideas?

TIA!

Andy

Re: How to "center center" an image

Posted: 2013-01-30T10:39:46-07:00
by fmw42
Your command should work. Perhaps you have an old version of IM that needs updating? What IM version and platform are you using?

Re: How to "center center" an image

Posted: 2013-01-30T10:42:03-07:00
by ultranerds
Mmm... this is what it says:

convert -version
Version: ImageMagick 6.5.8-8 2010-06-25 Q16 http://www.imagemagick.org
Copyright: Copyright (C) 1999-2010 ImageMagick Studio LLC
Features: OpenMP

Here is an example of what it outputs:

http://waaaant.com/uploads/large/40/tes ... Obz9Kl.jpg

...I think thats pretty up-to-date?

TIA

Re: How to "center center" an image

Posted: 2013-01-30T10:53:59-07:00
by Bonzo
Forget this post :(

Re: How to "center center" an image

Posted: 2013-01-30T10:56:31-07:00
by ultranerds
Sorry?

Re: How to "center center" an image

Posted: 2013-01-30T11:01:53-07:00
by Bonzo
Your version is 2009 - I posted before I looked it up.

Looking back there was a problem with extent and gravity fixed at version 6.4.3.5

Have you tried it without the ^ and see what happens. I would try a very simple command first and see if something else is causing the problem.

Re: How to "center center" an image

Posted: 2013-01-30T11:21:15-07:00
by ultranerds
Thanks for the reply. If I remove ^ from the dimensions, I get the same image:

http://waaaant.com/uploads/large/40/tes ... Obz9Kl.jpg

:/
I would try a very simple command first and see if something else is causing the problem.
"simple" as in? :)

TIA

Andy

Re: How to "center center" an image

Posted: 2013-01-30T12:52:02-07:00
by ultranerds
Hi,

I got my host to upgrade me to the latest version they were comfortable with:

Code: Select all

Version: ImageMagick 6.7.6-7 2013-01-30 Q16 http://www.imagemagick.org
Copyright: Copyright (C) 1999-2012 ImageMagick Studio LLC
Still got the same problem though :( Is there maybe another way of invoking IM to do what I want? I've only really dabbled with it (most of the time I just use it for straight forward "resize" facilities)

TIA

Andy

Re: How to "center center" an image

Posted: 2013-01-30T13:07:09-07:00
by Bonzo
Something simple would be ( where extent is bigger than your image ):

Code: Select all

convert7UFFBJ7XVryG2hEljnQH247FObz9Kl.jpg -background NavajoWhite -gravity center -extent 200x200 test-7UFFBJ7XVryG2hEljnQH247FObz9Kl.jpg
I have just noticed you do not have a background colour.

Are you using php or similar and when you tired "convert -version" was it through the code or via the cpanel?

I would guess you could have two versions of Imagemagick installed.

Re: How to "center center" an image

Posted: 2013-01-30T13:26:47-07:00
by fmw42
As Bonzo said, there may be two or more versions of IM installed in different locations. You may have to preface convert with the path to it. Ask you ISP what is the path to the latest version of convert that they just installed. Typically it is /usr/bin or /usr/local/bin. So perhaps by default, you are still going to the older version by leaving off the path to convert.

Re: How to "center center" an image

Posted: 2013-01-30T13:33:49-07:00
by ultranerds
Thanks for the replies guys. As far as I can tell its using the right one:
user@undevmac ~/waaaant.com/cgi-bin/admin/templates $ convert --version
Version: ImageMagick 6.7.6-7 2013-01-30 Q16 http://www.imagemagick.org
Copyright: Copyright (C) 1999-2012 ImageMagick Studio LLC
Features:

steveraf@user ~/waaaant.com/cgi-bin/admin/templates $ /usr/bin/convert --version
Version: ImageMagick 6.7.6-7 2013-01-30 Q16 http://www.imagemagick.org
Copyright: Copyright (C) 1999-2012 ImageMagick Studio LLC
Features:
A "whereis convert" gives me (as I would expect);

convert: /usr/bin/convert /usr/share/man/man1/convert.1.bz2

What command would you guys be using yourself? All it needs to do is:

1) Shrink to 200x200 (max)
2) This image then needs to be a fixed size of 200x200 (to fit in its placeholder on the site, which requires a fixed size)

TIA

Andy

Re: How to "center center" an image

Posted: 2013-01-30T13:49:18-07:00
by Bonzo
If your background is always the same you could composite your new image onto a standard background.

Code: Select all

convert -define jpeg:size=200x200 7UFFBJ7XVryG2hEljnQH247FObz9Kl.jpg -thumbnail 200x200^ background.jpg -gravity center -composite test-7UFFBJ7XVryG2hEljnQH247FObz9Kl.jpg

Re: How to "center center" an image

Posted: 2013-01-30T14:02:19-07:00
by ultranerds
Thanks - that just gives me a white image? (I used an example "blank" image that is the correct size)

http://waaaant.com/uploads/large/40/tes ... Obz9Kl.jpg

Any ideas?

TIA

Andy

Re: How to "center center" an image

Posted: 2013-01-30T14:35:01-07:00
by Bonzo
I do had the images the in the wrong order - you will also need to use brackets now ( ) on windows \( \) on linux.

Code: Select all

convert background.jpg \( -define jpeg:size=200x200 7UFFBJ7XVryG2hEljnQH247FObz9Kl.jpg -thumbnail 200x200^ \) -gravity center -composite test-7UFFBJ7XVryG2hEljnQH247FObz9Kl.jpg

Re: How to "center center" an image

Posted: 2013-01-30T14:45:07-07:00
by ultranerds
Hi,

Wahooooo we got there! This works:

Code: Select all

convert blank300.gif \( -define jpeg:size=300x300 7UFFBJ7XVryG2hEljnQH247FObz9Kl.jpg -thumbnail 300x300 \) -gravity center -composite test10-7UFFBJ7XVryG2hEljnQH247FObz9Kl.jpg
Thank you everyone for your help 8) (you can see these nice new images on the homepage btw: http://waaaant.com/ ... if you resize the window you will see its responsive, which is why I needed the fixed width images, so it scaled right =))

Cheers

Andy