wrong background color using extent option

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
stefano@BL
Posts: 5
Joined: 2009-03-15T15:04:52-07:00
Authentication code: 8675309

wrong background color using extent option

Post by stefano@BL »

I use the following command to resize a rectangle image and put it in a squared canvas with a white background.

Code: Select all

convert image.jpg -colorspace RGB -strip -resample 72 -resize 92x92 -background white -gravity center -extent 92x92 image4.jpg
The resize works good but the additional area that is added to have the image in 92x92 is black; I would like to have it in white.
In the command I use -background white, is it not enough?
What other option does I have to use?

And the image is note centered, even if I have used -gravity center

Thank you
bye
stefano
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: wrong background color using extent option

Post by fmw42 »

stefano@BL wrote:I use the following command to resize a rectangle image and put it in a squared canvas with a white background.

Code: Select all

convert image.jpg -colorspace RGB -strip -resample 72 -resize 92x92 -background white -gravity center -extent 92x92 image4.jpg
The resize works good but the additional area that is added to have the image in 92x92 is black; I would like to have it in white.
In the command I use -background white, is it not enough?
What other option does I have to use?

And the image is note centered, even if I have used -gravity center

Thank you
bye
stefano
Your command works fine for me on IM 6.5.0-0 Q16 Mac OSX Tiger. Perhaps you have an old IM version or one with a bug. What version are you using? Try upgrading.

But why are you using -strip -resample -resize, especially -resample. I don't think that is what you want. If you want to change the dpi without changing pixel resolution (which -resample does) use -density instead. You can get mostly the same from -thumbnail, which does a resize with -strip.

convert image.jpg -colorspace RGB -thumbnail 92x92 -background white -gravity center -extent 92x92 image4.jpg

see
http://www.imagemagick.org/script/comma ... #thumbnail
http://www.imagemagick.org/script/comma ... hp#density
http://www.imagemagick.org/script/comma ... p#resample
stefano@BL
Posts: 5
Joined: 2009-03-15T15:04:52-07:00
Authentication code: 8675309

Re: wrong background color using extent option

Post by stefano@BL »

Hi fmv42,
thank you for your answer.
I am using an older version, 6.2.8 on linux. I will try to update it.

I read better the documentation about -density, thank you for you suggestion.
bye
stefano
Post Reply