Created
May 23, 2019 15:18
-
-
Save jacmaes/22f03d9c3bc4aa837993f4a3b574ad14 to your computer and use it in GitHub Desktop.
Save external image and rename it in Processwire #pw
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// 1. We generate a static image from Mapbox's static Maps API. | |
// 2. We save it to an image field | |
// 3. We rename it to a more comprehensible filename, and then we add an extension (png by default for Mapbox). | |
// View investigacioncontemporanea.com -> "university" template for example of implementation. | |
if (!$page->image) { | |
$p = $page; | |
$p->of(false); | |
$p->image->add("https://api.mapbox.com/styles/v1/mapbox/dark-v10/static/pin-s-r+d29b31($long,$lat)/$long,$lat,$zoom,0,0/629x250?access_token=API_KEY_HERE"); | |
$p->image->first->rename("{$p->title}.png"); | |
$p->save(); | |
} else { | |
echo "<img src='{$page->image->url}' alt='$page->title'>"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment