variable_file.module in Variable Extra 7
File
variable_file/variable_file.module
View source
<?php
function variable_file_form_image_process($element, &$form_state, $form) {
$variable = $element['#variable'];
$element['#theme'] = 'image_widget';
$element['#attached']['css'][] = drupal_get_path('module', 'image') . '/image.css';
if ($element['#file']) {
$variables = array(
'style_name' => $variable['image style'],
'path' => $element['#file']->uri,
);
if (isset($element['#value']['width']) && isset($element['#value']['height'])) {
$variables['width'] = $element['#value']['width'];
$variables['height'] = $element['#value']['height'];
}
else {
$info = image_get_info($element['#file']->uri);
if (is_array($info)) {
$variables['width'] = $info['width'];
$variables['height'] = $info['height'];
}
else {
$variables['width'] = $variables['height'] = NULL;
}
}
$element['preview'] = array(
'#type' => 'markup',
'#markup' => theme('image_style', $variables),
);
$element['width'] = array(
'#type' => 'hidden',
'#value' => $variables['width'],
);
$element['height'] = array(
'#type' => 'hidden',
'#value' => $variables['height'],
);
}
return $element;
}