4

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: Map of building with single thumbnail

2
  • This seems some-what familiar in relation to using coordinates to set images Commented Dec 1, 2015 at 3:13
  • 1
    They use a loop. I tried it also but got nothing else than errors. But im going to give it a try again. Thanks for the link Commented Dec 1, 2015 at 3:29

1 Answer 1

4

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);
}
?>
Sign up to request clarification or add additional context in comments.

1 Comment

Nice! Glad the link helped out!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.