How to pad image in PythonMagick (or *Magick)?

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
pwnedd
Posts: 35
Joined: 2008-09-03T13:03:57-07:00

Re: How to pad image in PythonMagick (or *Magick)?

Post by pwnedd »

Hi Jerry,

I haven't tried using PythonMagick yet, but if you are interested, here is how you can do it using PHP:

Code: Select all

<?php
        // e.g. Pad left and right with 100px white bg
        $im = new Imagick("myImage.png");

        $white = new ImagickPixel( "white" );
        
        $im->borderImage($white, 100, 0);

        $im->writeImage("output.png");
?>
Padding add of the sides, or both top & bottom or left & right is pretty straight-forward. To pad just one corner however is a little tricker: you have to first
pad all sides, then remove the padding (via cropImage) that you don't want.

Check out the IMagick Docs for more info if you are interested.

Hope this helps.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: How to pad image in PythonMagick (or *Magick)?

Post by anthony »

For padding a corner you can append xc: images, or use Spilce to insert rows and columns. This addes the row/columns relative to gravity too.

See the Command Line examples, the API should also be available
http://www.imagemagick.org/Usage/crop/#splice
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply