-4

How to make php create an image like that?

enter image description here

(Obviously, without texts, borders, lines, arrows.)

miken32
  • 42,008
  • 16
  • 111
  • 154
Eduardo Dallmann
  • 423
  • 5
  • 14
  • 1
    The [PHP:GD](http://php.net/manual/en/book.image.php) docs, [A related question](http://stackoverflow.com/questions/645582/how-to-draw-a-graph-in-php), and [the generic google search](https://www.google.com/search?q=php%20make%20graph) might be good starting points – castis Jul 08 '16 at 00:04
  • How is this too broad? He's pretty clear on what he wants to do: make an image containing three other images with borders. it's only broad if you don't see the example image he gives. – Keith Tyler Jul 08 '16 at 19:23

1 Answers1

1

You could use GD library.

// Load the three image files:
$images[1]=imagecreatefromjpeg("file1.jpg");
$images[2]=imagecreatefromjpeg("file2.jpg");
$images[3]=imagecreatefromjpeg("file3.jpg");
// Determine their dimensions.
$totalx=$totaly=0;
for ($ix in $images) {
    $img=$images[$ix];
    $totalx+=imagesx($img); // get total width
    $totaly=max($totaly,imagesy($img)); // get maximum height
}
$xm=20; // side and in-between margin
$ym=20; // top and bottom margin
$totalx+=$xmargin*4; // 2 for the outsides and 2 for the in-betweens
$totaly+=$ymargin*2; // for top and bottom
$i=imagecreatetruecolor($totalx,$totaly);
$xstart=0; // where to place the next image
for ($ix in $images) {
    $img=$images[$ix];
    $xstart+=$imagesx($img)+$xm; // increase by this image's width plus buffer
    imagecopy($i,$img,$xstart,$ym,0,0,imagesx($img),imagesy($img));
}
imagepng($i); // this outputs the image data. if you want to write it to a file you can do that with imagepng($i,$filename).

http://php.net/manual/en/ref.image.php

Keith Tyler
  • 719
  • 4
  • 18
  • Keep in mind you need to use the right image loading function. For example if the source image is PNG then you need to use imagecreatefrompng() instead of imagecreatefromjpeg(). You can scan the filename or use mime-types to determine the image format and then call the appropriate imagefrom*() function -- fun fact, the end of those functions match the mime type values! Likewise if you want to output something other than PNG you have to use e.g. imagejpeg($i) instead of imagepng($i). – Keith Tyler Jul 08 '16 at 00:20
  • Also, if you want the images to be all the same size in the final image, you can use the desired w/h values instead of imagesx() and imagesy() in the imagecopy() call. In my example I presumed you wanted the images to be the same size as they were originally. – Keith Tyler Jul 08 '16 at 00:23