Adding multiple images to one image (with data from the database)

I tried everything I know for the last 3 days, but I can’t understand, so I hope someone can help me with this.

I want to get some records from a database. In the database for each individual record, a link to a thumbnail, x coordinate and specified y coordinate is indicated.

An image (building map) must be created starting with a blank building map (plattegrond.jpg). Then you need to add several sketches that contain numbers (see image below) on a coordinated one specified in the database. When all thumbnails are added, they need to be saved as something like Project1.jpg or something else.

$emptymap = "plattegrond.jpg"; // this is a map of a building
$newmap = "Project1.jpg"; // this must be the new map with the images

header('Content-type: image/jpeg');
$im = @imagecreatefromjpeg('maps/'.$emptymap) or die("Cannot Initialize new GD image stream");
$im2 = @imagecreatefromjpeg('thumbnails/'.$linkToThumbnail);
imagecopy($im, $im2, $xcoord, $ycoord, 0, 0, imagesx($im2), imagesy($im2));
imagejpeg($im, 'maps/'.$newmap, 100);
imagedestroy($im);
imagedestroy($im2);

Thumbnails already exist and all small images are saved as 1.jpg, 2.jpg, 3.jpg, etc.

, : , , ?

!

: Map of building with single thumbnail

+4
1

, , ! :)

<?php
$coords = array
   (
   array("2","100","200"),
   array("3","200","100"),
   array("4","250","30"),
   array("5","134","90")
   );
$arrlength = count($coords);

$map = "Project2.jpg";

for($x = 0; $x < $arrlength; $x++) {
    addThumb($map, $coords[$x][0], $coords[$x][1], $coords[$x][2]);
}

function addThumb($map, $thumb, $xcoord, $ycoord)
{ 
 $thumb .= ".jpg";
 $imMap = imagecreatefromjpeg('maps/'.$map);
 $imThumb = imagecreatefromjpeg('thumbnails/'.$thumb);
 imagecopy($imMap, $imThumb, $xcoord, $ycoord, 0, 0, imagesx($imThumb), imagesy($imThumb));
 imagejpeg($imMap, 'maps/'.$map, 100);
 imagedestroy($imMap);
 imagedestroy($imThumb);
}
?>
+4

Source: https://habr.com/ru/post/1618050/


All Articles