Playing around with a custom validator that will take the path of an image, get the height and width dimensions and save those values to the 2 extra editable fields within the same template.
I am getting the dimensions but could use little assistance with getting the values to the form to save, if even possible.
Editable's in template:
In kfunctions.php:
Thanks.
I am getting the dimensions but could use little assistance with getting the values to the form to save, if even possible.
Editable's in template:
- Code: Select all
<cms:editable name='testimage' label='Test image' type='image' order='1' validator='getImgStats' />
<cms:editable name='imgwidth' label='img width' type='text' order='2' />
<cms:editable name='imgheight' label='img width' type='text' order='3' />
In kfunctions.php:
- Code: Select all
function getImgStats($field) {
$image = trim($field->get_data());
try {
list($width, $height) = getimagesize($image);
// save width and height into editables imgheight and imgwidth
$field->page->_fields['imgheight'] = $height;
$field->page->_fields['imgwidth'] = $width;
} catch (Exception $e) {
}
}
Thanks.