wCMF  3.6
 All Classes Namespaces Files Functions Variables Groups Pages
function.image_size.php
Go to the documentation of this file.
1 <?php
2 /**
3  * wCMF - wemove Content Management Framework
4  * Copyright (C) 2005-2014 wemove digital solutions GmbH
5  *
6  * Licensed under the terms of any of the following licenses
7  * at your choice:
8  *
9  * - GNU Lesser General Public License (LGPL)
10  * http://www.gnu.org/licenses/lgpl.html
11  * - Eclipse Public License (EPL)
12  * http://www.eclipse.org/org/documents/epl-v10.php
13  *
14  * See the license.txt file distributed with this work for
15  * additional information.
16  *
17  * $Id$
18  */
19 
20 /*
21 * Smarty plugin
22 * -------------------------------------------------------------
23 * File: function.image_size.php
24 * Type: function
25 * Name: image_size
26 * Purpose: determine the size of an image file and assign width
27 * and heigth to smarty variables (widthvar or heightvar parameter
28 * may be omitted, if the result should be ignored). an optional
29 * boolean parameter halfsize may be used to return sizes divided
30 * by two (usefull for retina displays).
31 * Usage: e.g. {image_size image=$node->getImage() widthvar="width" heightvar="height"}
32 * -------------------------------------------------------------
33 */
34 function smarty_function_image_size($params, &$smarty)
35 {
36  $size = getimagesize($params['image']);
37  $dividyByTwo = isset($params['halfsize']) && $params['halfsize'] == true;
38  $width = $dividyByTwo ? intval($size[0]/2) : $size[0];
39  $height = $dividyByTwo ? intval($size[1]/2) : $size[1];
40  if (isset($params['widthvar'])) {
41  $smarty->assign($params['widthvar'], $width);
42  }
43  if (isset($params['heightvar'])) {
44  $smarty->assign($params['heightvar'], $height);
45  }
46 }
47 ?>
smarty_function_image_size($params, &$smarty)