function.image_size.php
1 <?php
2 /**
3  * wCMF - wemove Content Management Framework
4  * Copyright (C) 2005-2015 wemove digital solutions GmbH
5  *
6  * Licensed under the terms of the MIT License.
7  *
8  * See the LICENSE file distributed with this work for
9  * additional information.
10  */
11 
12 /*
13 * Smarty plugin
14 * -------------------------------------------------------------
15 * File: function.image_size.php
16 * Type: function
17 * Name: image_size
18 * Purpose: determine the size of an image file and assign width
19 * and heigth to smarty variables (widthvar or heightvar parameter
20 * may be omitted, if the result should be ignored). an optional
21 * boolean parameter halfsize may be used to return sizes divided
22 * by two (usefull for retina displays).
23 * Usage: e.g. {image_size image=$node->getImage() widthvar="width" heightvar="height"}
24 * -------------------------------------------------------------
25 */
26 function smarty_function_image_size($params, \Smarty_Internal_Template $template) {
27  $size = @getimagesize($params['image']);
28  $dividyByTwo = isset($params['halfsize']) && $params['halfsize'] == true;
29  $width = $dividyByTwo ? intval($size[0]/2) : $size[0];
30  $height = $dividyByTwo ? intval($size[1]/2) : $size[1];
31  if (isset($params['widthvar'])) {
32  $template->assign($params['widthvar'], $width);
33  }
34  if (isset($params['heightvar'])) {
35  $template->assign($params['heightvar'], $height);
36  }
37 }
38 ?>