簡體   English   中英

如何在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);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM