Adding whitespace

IMagick is a native PHP extension to create and modify images using the ImageMagick API. ImageMagick Studio LLC did not write nor does it maintain the IMagick extension, however, IMagick users are welcome to discuss the extension here.
Post Reply
musicmaster
Posts: 7
Joined: 2016-02-14T07:50:18-07:00
Authentication code: 1151

Adding whitespace

Post 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?
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Adding whitespace

Post by snibgo »

Code: Select all

convert in.png -gravity center -extent 200x200 out.png
See http://www.imagemagick.org/script/comma ... php#extent
snibgo's IM pages: im.snibgo.com
musicmaster
Posts: 7
Joined: 2016-02-14T07:50:18-07:00
Authentication code: 1151

Re: Adding whitespace

Post 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.
User avatar
dlemstra
Posts: 1570
Joined: 2013-05-04T15:28:54-07:00
Authentication code: 6789
Contact:

Re: Adding whitespace

Post by dlemstra »

You are looking for the following method: http://php.net/manual/en/imagick.extentimage.php (-extent)
.NET + ImageMagick = Magick.NET https://github.com/dlemstra/Magick.NET, @MagickNET, Donate
musicmaster
Posts: 7
Joined: 2016-02-14T07:50:18-07:00
Authentication code: 1151

Re: Adding whitespace

Post by musicmaster »

Hi dlemstra,

That solves my problem. Thanks.
Post Reply