我对 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");
?>
如果我从这个开始:
我得到这个结果
后来我添加了黑色轮廓,这样你就可以看到图像的范围。