Have a question about CiviCRM? Get it answered quickly at the new CiviCRM Stack Exchange Q+A siteThis forum was archived on 25 November 2017. Learn more.How to get involved.What to do if you think you've found a bug.
function get_civicrm_image($id, $dimensions=array(200,200)) { civicrm_initialize(); require_once('api/File.php'); // get the file details $file = array_shift(crm_get_file(array('id'=>$id))); $filename = $file['uri']; $root = $_SERVER['DOCUMENT_ROOT']; $file_ext = strrchr($filename, '.'); $file_base = substr($filename, 0, 0 - strlen($file_ext)); $old_path = $root . '/' . file_directory_path() . '/civicrm/custom/' . $filename; $new_file = file_directory_path() . '/civicrm/custom/' . $file_base . '_' . $dimensions[0] . 'x' . $dimensions[1] . $file_ext; if(!file_exists($root . '/' . $new_file)) { image_scale_and_crop($old_path, $root . '/' . $new_file, $dimensions[0], $dimensions[1]); } return $new_file;}
$img_uri = url(get_civicrm_image($fields['image_1']->content, array(300, 200)));
I'm assuming that image_scale_and_crop works only in drupal ?
$root = $_SERVER['DOCUMENT_ROOT'];
drupal_rebuild_theme_registry(); // clear theme cache on each page load