How to resize civicrm images(uploaded via webform) in Drupal views. The images are getting displayed but the width and height are of the size when they upload images..
3 Answers
2 solutions come to mind
- Use css to give each image a
max-width
property. This will make images appear correctly, but won't save bandwidth as the full image will be downloaded and scaled client-side. - Use a drupal module such as Image Resize Filter
If you need more advanced resizing / image transformation options, you can create a custom template file for the image URL field and use drupal image style (admin/config/media/image-styles) to define the required conversion.
As CiviCRM is protecting the files (we don't have the files urls in the database since 4.4.4 ?), you need to use imagecache_external (didn't manage to make image_style_url work). The drawback of this module is that the image is duplicated in drupal.
Anyway, to make this work :
install imagecache_external, go to the configuration page (
http://YOUR_SITE/admin/config/media/imagecache_external
) and add YOUR_SITE to the white listcreate a style
http://YOUR_SITE/admin/config/media/image-styles/add
configure the view as needed and add the CiviCRM Image URL field
Edit the view -> Advanced -> Information
Find the file name corresponding to the field you want to customize and create the file with this file name in
YOUR_THEME/templates/
Paste the following code (replace
'thumbnail'
with the style name you have created) :<?php if ($row->{$field->field_alias} != '') { print theme('imagecache_external', array( 'path' => $row->{$field->field_alias}, 'style_name'=> 'thumbnail')); } ?>
back to Edit the view -> Advanced -> Information -> Rescan templates file and then save the view.

- 395
- 2
- 10
-
This didn't quite work - see my answer below for template changes – Matthew Wire Mar 22 '19 at 12:49
This didn't quite work on a drupal 7 / CiviCRM 5.10+ system (don't know if it still works on earlier).
To make it work put this in the template file:
<?php
$path = $field->render($row);
if (!empty($path)) {
print theme('imagecache_external', array(
'path' => $path,
'style_name'=> 'thumbnail'));
}
?>

- 101