douzhi4830 2014-12-02 20:45
浏览 72

Php图像从多个图像合并

I want to make a image from multiple image.In my image list have maximum 6 image.i want to add all image side by side.as example


1st image          |      2nd image

3rd image          |      4th image

5th image          |      6th image

I am writing a code that makes image Vertically.

my code

<?php



$numberOfImages = 6;
$x = 940;
$y = 920;
$background = imagecreatetruecolor($x, $y*6);


$firstUrl = 'e.jpg';

$secondUrl = 'f.jpg';

$thirdUrl = 'f.jpg';

$fourthUrl = 'e.jpg';

$fiveUrl = 'f.jpg';

$sixUrl = 'f.jpg';

$outputImage = $background;

$first = imagecreatefromjpeg($firstUrl);
$second = imagecreatefromjpeg($secondUrl);
$third = imagecreatefromjpeg($thirdUrl);



imagecopymerge($outputImage,$first,0,0,0,0, $x, $y,100);
imagecopymerge($outputImage,$second,0,$y,0,0, $x, $y,100);
imagecopymerge($outputImage,$third,0,$y*2,0,0, $x, $y,100);

imagejpeg($outputImage, APPLICATION_PATH .'test.jpg');

imagedestroy($outputImage);




?>

But i want to placed image dynamically cause image item could be 4 or 5 or 6 or 1 or 2 or 3

But how?

  • 写回答

1条回答 默认 最新

  • dongyi1490 2014-12-02 20:59
    关注

    Check out Merge two images in php

    Adapt that function to either put two images side by side (taking two parameters, each images) and also adapt it to put three images vertically (as it starts with two, you're just adding a third). This second adaptation would take three parameters of the three images to join.

    Then call the functions, nesting one in the other, such as:

    join3(join2($firstURL, $secondURL), 
          join2($thirdURL, $fourthURL), 
          join2($fifthURL, $sixthURL));
    

    and you can set your URL parameters to whatever you want to dynamically call the function.

    评论

报告相同问题?

悬赏问题

  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?