13.04.2020, 22:51
Hello I am trying to create the same thing just replacing the red square with image
Thats the code but its not the same location where map.php?x=1450&y=2770
Thats the code but its not the same location where map.php?x=1450&y=2770
PHP Code:
<?php
$img = imagecreatefromjpeg("map.jpg");
$sim = imagecreatefrompng("pin.png");
if( isset($_GET["x"]) && isset($_GET["y"]) ) {
// the map is GTA SAn andreas is 6000x6000
// the image that i use is 800x800 6000/800 = 7.5
$x = $_GET["x"]/7.5;
$y = $_GET["y"]/7.5;
// 0.0 0.0 is at the center of the map, in PHP 0.0 0.0 is in the top left corner, so I added / substracted 400. the map is 800x800 px, 400x400 is at the center of the map.
$x = $x + 400;
$y = -($y - 400);
$sx = imagesx($img);
$sy = imagesy($sim);
$marge_right = $_GET["x"]/5.5;
$marge_bottom = $_GET["y"]/5.5;
imagecopy($img, $sim, imagesx($img) - $sx - $marge_right, imagesy($img) - $sy - $marge_bottom, 0, 0, imagesx($sim), imagesy($sim));
}
header ('Content-Type: image/png');
imagepng($img);
imagepng($sim);
imagedestroy($img);
imagedestroy($sim);
?>