Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
I'm trying to render an image through a theme preprocess function and am finding that I can't seem to render the file through an image style with EPSAcrop correctly. Rather, this code below seems to crop the image to the dimensions specified in the EPSAcrop dimensions for the 'program_view' image style, but it doesn't crop from the coordinates specified on the field. It seems to be cropping directly from the center of the image, and I'm wondering if I somehow need to pass coordinates from the field to the theme('image_style'...) function.
function theme_preprocess_node(&$vars) {
$image = isset($vars['field_image']) ? $vars['field_image'][$lang][0]: array();
/*
* Preparing teaser image markup
*/
if(!empty($image)) {
$imagestyle = 'program_view';
$filename = $image['filename'];
$src_uri = file_build_uri($filename);
$dest_uri = image_style_path($imagestyle, $src_uri);
$style = image_style_load($imagestyle);
if (!file_exists($dest_uri)) {
image_style_create_derivative($style, $image['uri'], $dest_uri);
}
$vars['image'] = theme(
'image_style',
array(
'path' => $dest_uri,
'style_name' => $imagestyle
)
);
}
}
Any thoughts on how to do this successfully?
Comments
Comment #2
aaron.silber CreditAttribution: aaron.silber commentedComment #3
aaron.silber CreditAttribution: aaron.silber commentedComment #4
immoreel CreditAttribution: immoreel at Finalist commentedOk, I guess you already found a workaround, but if you didn't you can try this: