Last active
December 12, 2018 17:19
-
-
Save jonleverrier/7a79b2bdb678f230f66ad5e1bec2ee71 to your computer and use it in GitHub Desktop.
getImgSizeFromUrl snippet for MODX. Retrieves the height and width of an image from a remote url.
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 | |
/** | |
* getImgSizeFromUrl snippet for MODX | |
* Retrieves the height and width of an image from a remote url | |
* | |
* example usage: [[!getImgSizeFromUrl? &url='https://path/to/myimg.jpg' &tpl=`myTpl`]] | |
* placeholders to use in the myTpl chunk are [[+height]]] and [[+width]] | |
* | |
* @author Jon Leverrier (jon@youandmedigital.com) | |
* @version 1.0 | |
* @since 10th December 2017 | |
*/ | |
// if the url or tpl is empty | |
if (empty($url && $tpl)) { | |
return; | |
} | |
else { | |
// fetch image from remote url | |
// take width and height values from image | |
list($width, $height) = getimagesize($url); | |
// route width and height values to placeholders in tpl chunk | |
$output = $modx->getChunk($tpl,array( | |
'width' => $width, | |
'height' => $height, | |
)); | |
return $output; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment