Page 1 of 1

Adding whitespace

Posted: 2016-02-14T07:59:58-07:00
by musicmaster
What is the best way to add whitespace?

I have an image of 200x150 and it needs to be displayed in a square format (200x200) with 25 pixels whitespace above and below the image to fill out.

The only example I could find first stretches the image to fill the square and then uses the borderimage command to put borders above and below the image. But it seems to me that will both waste a lot of time and deteriorate the quality of the image.

Can some Imagick guru enlighten me on this subject?

Re: Adding whitespace

Posted: 2016-02-14T09:15:19-07:00
by snibgo

Code: Select all

convert in.png -gravity center -extent 200x200 out.png
See ... php#extent

Re: Adding whitespace

Posted: 2016-02-14T10:01:44-07:00
by musicmaster
Hi Snibgo, Thanks.

Is it also possible to do this with the PHP object? There is an setImageGravity method but it takes only one argument and offers not the possibility to define a second image.

Re: Adding whitespace

Posted: 2016-02-14T10:06:49-07:00
by dlemstra
You are looking for the following method: (-extent)

Re: Adding whitespace

Posted: 2016-02-14T10:45:27-07:00
by musicmaster
Hi dlemstra,

That solves my problem. Thanks.