如何使用php imagick合并图像

如何使用php imagick合并图像,php,imagick,Php,Imagick,我对使用php imagick非常陌生。 基本上我想合并两个图像。 我已经把这个编码了 $logo = new Imagick("img/logo.png"); $name ="Jhon N. Doe"; $title ="Web Programmer"; $address= "abc road xyz"; $website = "www.acfh.com"; $phone = "0555555"; $email ="mizff@yaho

我对使用php imagick非常陌生。 基本上我想合并两个图像。 我已经把这个编码了

    $logo = new Imagick("img/logo.png");
    $name  ="Jhon N. Doe";
    $title ="Web Programmer";
    $address= "abc road xyz";
    $website = "www.acfh.com";
    $phone = "0555555";
    $email ="mizff@yahoo.com";

    $image = new Imagick();
    $draw = new ImagickDraw();
    $pixel = new ImagickPixel( '#f5f5f5' );

    $image->newImage(350, 170, $pixel);

    //$logo->newImage(100, 100,$logo);
    /* Black text */
    $draw->setFillColor('#6b6a6a');

    /* Font properties */
    $draw->setFont('./font/MyriadPro-Regular.otf');
    $draw->setFontSize(10);

    /* Create text */
    $image->annotateImage($draw, 230, 150, 0, $email);
    $image->annotateImage($draw, 102, 75, 0, $title);
    $image->annotateImage($draw, 10, 150, 0, $address);
    $image->annotateImage($draw, 230, 160, 0, $phone);


    /* Output the image */

    //for name 
    $draw->setFillColor('#333333');
    $draw->setFontSize( 30 );
    $image->annotateImage($draw, 30, 60, 0, $name);

    $draw->setGravity(Imagick::GRAVITY_CENTER);
    $image->compositeImage($logo, Imagick::COMPOSITE_DEFAULT, 230, 20);
    $image->resetIterator();
    $combined = $image->appendImages(true);
    $combined->setResolution(72,72);
    $combined->setImageFormat("jpg");
    header("Content-Type: image/jpg");
    echo $combined;
    }

这是一张卡片。现在我想在A4或leageal页面上重复多次,并将其保存为pdf。请帮助我。

从代码中删除以下行

$image->resetIterator();
$combined = $image->appendImages(true);
header("Content-Type: image/jpg");
echo $combined;
还可以使用compositeimage()函数组合图像

/* Set new imagick object with required height and width based on the dimension of your print paper*/
/* add the following code */

$output = new Imagick();
//sample image. width is double to your actual card width which was 350px. set height as required
$output->newimage( 700, 842, "none");

/* Add the Card to the blank image that we created */

$output->compositeimage($image->getimage(), Imagick::COMPOSITE_COPY, 0, 0);
$output->compositeimage($image->getimage(), Imagick::COMPOSITE_COPY, 350, 0);
您可以将上面的代码放在一个循环中,自动将卡片缝合到最终图像中的不同位置

/* sample example */ 

$height = "your card's height";
$width = "your card's width";

for( $row=0; $row<5 ; $row++ ){

    for($col=0; $col<2; $col++){
    $output->compositeimage($image->getimage(), Imagick::COMPOSITE_COPY, $row*$height, $col*$width);
    }
}

/* write you file to some file*/
$output->writeimage("/path-to-your-file.jpg");
$output->destroy();
/*示例*/
$height=“您的卡的高度”;
$width=“您的卡的宽度”;
对于($row=0;$rowgetimage(),Imagick::COMPOSITE_COPY,$row*$height,$col*$width);
}
}
/*将您的文件写入某个文件*/
$output->writeimage(“/path to your file.jpg”);
$output->destroy();

从代码中删除以下行

$image->resetIterator();
$combined = $image->appendImages(true);
header("Content-Type: image/jpg");
echo $combined;
还可以使用compositeimage()函数组合图像

/* Set new imagick object with required height and width based on the dimension of your print paper*/
/* add the following code */

$output = new Imagick();
//sample image. width is double to your actual card width which was 350px. set height as required
$output->newimage( 700, 842, "none");

/* Add the Card to the blank image that we created */

$output->compositeimage($image->getimage(), Imagick::COMPOSITE_COPY, 0, 0);
$output->compositeimage($image->getimage(), Imagick::COMPOSITE_COPY, 350, 0);
您可以将上面的代码放在一个循环中,自动将卡片缝合到最终图像中的不同位置

/* sample example */ 

$height = "your card's height";
$width = "your card's width";

for( $row=0; $row<5 ; $row++ ){

    for($col=0; $col<2; $col++){
    $output->compositeimage($image->getimage(), Imagick::COMPOSITE_COPY, $row*$height, $col*$width);
    }
}

/* write you file to some file*/
$output->writeimage("/path-to-your-file.jpg");
$output->destroy();
/*示例*/
$height=“您的卡的高度”;
$width=“您的卡的宽度”;
对于($row=0;$rowgetimage(),Imagick::COMPOSITE_COPY,$row*$height,$col*$width);
}
}
/*将您的文件写入某个文件*/
$output->writeimage(“/path to your file.jpg”);
$output->destroy();