Page 1 of 1

append images vertically using MagickWand C API.

Posted: 2017-04-21T03:32:22-07:00
by rpatelob
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;
} 
 

Re: append images vertically using MagickWand C API.

Posted: 2017-04-21T03:53:35-07:00
by snibgo
The source code for MagickAppendImages() is in magick-image.c. The comments tell you how to "stack them top-to-bottom".

Re: append images vertically using MagickWand C API.

Posted: 2017-04-21T04:04:36-07:00
by rpatelob
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