append images vertically using MagickWand C API.

The MagickWand interface is a new high-level C API interface to ImageMagick core methods. We discourage the use of the core methods and encourage the use of this API instead. Post MagickWand questions, bug reports, and suggestions to this forum.
Post Reply
rpatelob
Posts: 62
Joined: 2017-04-17T22:17:01-07:00
Authentication code: 1151

append images vertically using MagickWand C API.

Post by rpatelob » 2017-04-21T03:32:22-07:00

I have multiple images and I need to append them and convert it to one image. For that I wrote below C program, it works fine except it appends images horizontally. How can I append images one after another?

For example using

Code: Select all

convert +append 
appends images horizontally and

Code: Select all

convert -append
append vertically. I want to do it vertically.

Code: Select all

  
int main(int argc, const char * argv[]){
    MagickWand * wandG1, * wandG2, * wandG3, * wandG4;
    wandG = NewMagickWand();
    MagickReadImage(wandG, "lala.jpg");
    
    wandG1 = CloneMagickWand(wandG);
    wandG2 = CloneMagickWand(wandG);
    wandG3 = CloneMagickWand(wandG);
    
    MagickRollImage(wandG1, 2, 0);
    MagickWriteImage(wandG1,"tile2x0.jpg");

    MagickRollImage(wandG2, 4, 0);
    MagickWriteImage(wandG2,"tile4x0.jpg");

    MagickRollImage(wandG3, 6, 0);
    MagickWriteImage(wandG3,"tile6x0.jpg");

    MagickSetLastIterator(wandG);
    MagickAddImage(wandG, wandG1);
    MagickAddImage(wandG, wandG2);
    MagickAddImage(wandG, wandG3);
    MagickSetFirstIterator(wandG);
    wandG4 = MagickAppendImages(wandG,MagickFalse);
    MagickWriteImage(wandG4,"tile.jpg");
    
    if(wandG)wandG = DestroyMagickWand(wandG);
    if(wandG)wandG1 = DestroyMagickWand(wandG1);
    if(wandG)wandG2 = DestroyMagickWand(wandG2);
    if(wandG)wandG3 = DestroyMagickWand(wandG3);
    
    MagickWandTerminus();
    return 0;
} 
 

snibgo
Posts: 9391
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: append images vertically using MagickWand C API.

Post by snibgo » 2017-04-21T03:53:35-07:00

The source code for MagickAppendImages() is in magick-image.c. The comments tell you how to "stack them top-to-bottom".
snibgo's IM pages: im.snibgo.com

rpatelob
Posts: 62
Joined: 2017-04-17T22:17:01-07:00
Authentication code: 1151

Re: append images vertically using MagickWand C API.

Post by rpatelob » 2017-04-21T04:04:36-07:00

snibgo wrote:
2017-04-21T03:53:35-07:00
The source code for MagickAppendImages() is in magick-image.c. The comments tell you how to "stack them top-to-bottom".
Thanks a lot snibgo, I haven't noticed the second parameter of that function.

Code: Select all

MagickAppendImages(wandG,MagickTrue);
With this it's working now. I just need to change second argument to MagickTrue

Post Reply