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

aaronlsilber created an issue. See original summary.

aaron.silber’s picture

Title: Rendering an image programatically falls back to jcrop. » Rendering an image programmatically using EPSAcrop-enabled image style uses incorrect coordinates.
aaron.silber’s picture

Version: » 7.x-2.4
Category: Support request » Bug report
immoreel’s picture

Ok, I guess you already found a workaround, but if you didn't you can try this:

...
$src_uri = file_build_uri($filename);
    $dest_uri = image_style_path($imagestyle, $src_uri);

    // Add the name of the image style to the globals array.
    $GLOBALS['jcrop_style'] = $imagestyle;

    $style = image_style_load($imagestyle);

    if (!file_exists($dest_uri)) {
     ...