如何在php imagemagick中将图像分成三个相等的部分,并将一些填充和输出结合为单个图像 [英] how to divide image into three equal parts in php imagemagick and combine with some padding and output as single image

查看:105
本文介绍了如何在php imagemagick中将图像分成三个相等的部分,并将一些填充和输出结合为单个图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在imagemagick PHP库的帮助下将图像分成三个部分作为triptych。我在这里看到了相同的例子

I want to display an image into three parts as triptych with the help of imagemagick PHP library. I saw the same example here

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

任何人都可以帮我解决这个问题

Can anyone help me on this issue please

推荐答案

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

I am hopeless at PHP but something like this seems to work for me:

#!/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");
?>

如果我从这开始:

我认为这是一个结果

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

I added the black outline afterwards so you can see the extent of the image.

这篇关于如何在php imagemagick中将图像分成三个相等的部分,并将一些填充和输出结合为单个图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆