如何在 php imagemagick 中将图像分成三等份并结合一些填充并输出为单个图像

how to divide image into three equal parts in php imagemagick and combine with some padding and output as single image

我想借助 imagemagick PHP 库将图像分成三部分显示为三联画。我在这里看到了同样的例子

http://www.rubbleimages.com/Canvas.php.

谁能帮我解决这个问题

我对 PHP 感到绝望,但这样的事情似乎对我有用:

#!/usr/local/bin/php -f
<?php

   $padding=10;
   $info = getimagesize("input.jpg");
   $width=$info[0];
   $height=$info[1];

   // Calculate dimensions of output image
   $canvasWidth=$width+4*$padding;
   $canvasHeight=$height+2*$padding;

   // create white canvas
   $output = imagecreatetruecolor($canvasWidth, $canvasHeight);
   $background = imagecolorallocate($output, 255, 255, 255);
   imagefill($output, 0, 0, $background);

   // read in original image
   $orig = imagecreatefromjpeg("input.jpg");

   // copy left third to output image
   imagecopy($output, $orig,$padding,             $padding,             0, 0, $width/3, $height);
   // copy central third to output image
   imagecopy($output, $orig,2*$padding+$width/3,  $padding,      $width/3, 0, $width/3, $height);
   // copy right third to output image
   imagecopy($output, $orig,3*$padding+2*$width/3,$padding,    2*$width/3, 0, $width/3, $height);

   // save output image
   imagejpeg($output,"result.jpg");
?>

如果我以此开头:

我得到这个结果

之后我添加了黑色轮廓,以便您可以看到图像的范围。

$cmd = " convert $photo  -crop 33.5%x100%  +repage  -raise 5x1      "."    monet_horizontal_%d.jpg";

exec($cmd);

$cmd = " convert monet_horizontal_0.jpg wt.png monet_horizontal_1.jpg wt.png monet_horizontal_2.jpg  +append "."  abc.jpg";

exec($cmd);