function iss_preprocess_image in Image Style Selector 7.2
Implements hook_preprocess_image().
File
- ./
iss.module, line 217
Code
function iss_preprocess_image(&$vars) {
if (variable_get('iss_apply_method', 'default') == 'preprocess_images' && isset($vars['style_name'])) {
// TODO: How to handle another stream wrappers?
//$wrappers = file_get_stream_wrappers();
//foreach ($wrappers as $wrapper_name => $wrapper_info) {
// $wrapper_path = file_stream_wrapper_get_instance_by_scheme($wrapper_name)->getDirectoryPath();
//}
// For now we only handling public schema.
$old_style = $vars['style_name'];
$schema = 'public';
$old_style_part = "/styles/{$vars['style_name']}/{$schema}/";
$url_parsed = drupal_parse_url($vars['path']);
$path_array = explode($old_style_part, $url_parsed['path']);
if (isset($path_array[1])) {
$original_image_uri = "{$schema}://" . $path_array[1];
$new_style = db_query('SELECT iss.target_style FROM iss_styles iss LEFT JOIN file_managed fm ON fm.fid = iss.fid WHERE fm.uri = :uri AND iss.source_style = :style', array(
':style' => $old_style,
':uri' => $original_image_uri,
))
->fetchField();
if ($new_style) {
$vars['iss_source_style_name'] = $old_style;
$vars['style_name'] = $new_style;
$new_style_path = image_style_url($new_style, $original_image_uri);
$vars['path'] = $new_style_path;
}
}
}
}