PHP code example of knyazevdev / gpx2png

1. Go to this page and download the library: Download knyazevdev/gpx2png library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

knyazevdev / gpx2png example snippets

 php
 Gpx2Png\Gpx2Png;

$gpx = new Gpx2Png();
$gpx2png->loadFile($gpxTrackFile);

$res = $gpx2png->generateImage();
$res->saveToFile($target_file);
 php
 Gpx2Png\Gpx2Png;
use Gpx2Png\Models\Overlays\DrawParamsPoint;
use Gpx2Png\Models\Point;

// prepare points set from own source 

$points = array();
foreach ($mypoints as $mypoint) {
    $points[] = new Point($mypoint['lat'], $mypoint['lon'], $point['timestamp']);
}

// load points

$gpx2png->loadPoints($points);

// set custom draw params

$gpx2png->drawParams->track->color = "black";
$gpx2png->drawParams->track->opacity = "0.3";
$gpx2png->drawParams->track->startPoint->color = "yellow";
$gpx2png->drawParams->track->distanceLabel->text_size = 20;
$gpx2png->drawParams->track->distanceLabel->text_color = 'red';

// set osm source type

$gpx2png->setMapSourceName("osm_topo");

// set custom tiles cache directory
// default: sys_get_temp_dir().'/tiles'

$gpx2png->mapSource->setTilesDirectory(__DIR__.'/tiles');

// receive result

$res = $gpx2png->generateImage();

// add extra overlays

$extraPoint = $points[mt_rand(0, count($points)-1)];
$drawParamsPoint = new DrawParamsPoint();
$drawParamsPoint->setTemplate(DrawParamsPoint::TPL_LIVE_POINT);

$res->image->drawPoint($extraPoint, $drawParamsPoint);

// save or output file

$res->saveToFile("result.png");
$res->output();