function _outline_designer_validate_image_resolution in Outline Designer 6
Same name and namespace in other branches
- 7 outline_designer.module \_outline_designer_validate_image_resolution()
File
- ./
outline_designer.module, line 782 - Massive usability improvement for quickly structuring / creating content.
Code
function _outline_designer_validate_image_resolution(&$file, $dimensions) {
$errors = array();
// Check first that the file is an image.
if ($info = image_get_info($file->filepath)) {
// Check if the icon matches the given dimensions.
list($width, $height) = explode('x', $dimensions);
if ($info['width'] != $width || $info['height'] != $height) {
// Try to resize the image to fit the dimensions if it doesn't.
if (image_get_toolkit() && image_scale_and_crop($file->filepath, $file->filepath, $width, $height)) {
drupal_set_message(t('The image was resized to the allowed dimensions of %dimensions pixels.', array(
'%dimensions' => $dimensions,
)));
// Clear the cached filesize and refresh the image information.
clearstatcache();
$info = image_get_info($file->filepath);
$file->filesize = $info['file_size'];
}
else {
$errors[] = t('Image dimensions need to be %dimensions pixels.', array(
'%dimensions' => $maximum_dimensions,
));
}
}
}
return $errors;
}