简体   繁体   中英

Adding multiple images on single image (with data from database)

I've tried everything i know for the last 3 days, but can't figure it out, so i hope someone could help me on this one.

I want to get multiple records from a database. In the database is for every single record the link to a thumbnail, x-coordinate and an y-coordinate specified.

The image (a map of a building) must be created starting with an empty map of a building (plattegrond.jpg). Then, multiple thumbnails must be added which contains numbers (see image below) on the coordinated specified in the database. When all the thumbnails are added, it must be saved as something like Project1.jpg or whatever.

$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);

The thumbnails already exists and are all small images saved as 1.jpg, 2.jpg, 3.jpg, etc.

So, in summary: How do i put multiple images with coordinates, which are specified in a database , on that single image?

All suggestions are welcome!

This is a preview of a map with a single thumbnail: 建筑物地图与单个缩略图

With the help of Darren his link, i managed to figure it out, finaly! I can sleep again :)

<?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);
}
?>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM