CiviCRM Community Forums (archive)

*

News:

Have a question about CiviCRM?
Get it answered quickly at the new
CiviCRM Stack Exchange Q+A site

This forum was archived on 25 November 2017. Learn more.
How to get involved.
What to do if you think you've found a bug.



  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM »
  • Using Drupal Modules (Moderator: Donald Lobo) »
  • Custom data image, Drupal Views, Thumbnails?
Pages: 1 ... 3 4 [5] 6 7

Author Topic: Custom data image, Drupal Views, Thumbnails?  (Read 31189 times)

fm

  • I post occasionally
  • **
  • Posts: 80
  • Karma: 1
Re: Custom data image, Drupal Views, Thumbnails?
March 11, 2010, 08:50:54 pm
Yes, that's the code. Here's a cut-and-paste from the template.php file:

Code: [Select]
// Clear Theme cache. Remove before going live.
drupal_rebuild_theme_registry(); // clear theme cache on each page load

Here are the entire contents of of the views theme file:

Code: [Select]
<?php
// $Id: views-view-fields.tpl.php,v 1.6 2008/09/24 22:48:21 merlinofchaos Exp $
/**
 * @file views-view-fields.tpl.php
 * Default simple view template to all the fields as a row.
 *
 * - $view: The view in use.
 * - $fields: an array of $field objects. Each one contains:
 *   - $field->content: The output of the field.
 *   - $field->raw: The raw data for the field, if it exists. This is NOT output safe.
 *   - $field->class: The safe class id to use.
 *   - $field->handler: The Views field handler object controlling this field. Do not use
 *     var_export to dump this object, as it can't handle the recursion.
 *   - $field->inline: Whether or not the field should be inline.
 *   - $field->inline_html: either div or span based on the above flag.
 *   - $field->separator: an optional separator that may appear before a field.
 * - $row: The raw result object from the query, with all data it fetched.
 *
 * @ingroup views_templates
 */
?>

<?php $image_uri = url(get_civicrm_image($fields['image_1']->content)); echo $image_uri; ?>
<img src="<?php echo $image_uri; ?>" />

lentilsoup

  • I post frequently
  • ***
  • Posts: 134
  • Karma: 6
Re: Custom data image, Drupal Views, Thumbnails?
March 11, 2010, 10:38:34 pm
What are the complete contents of the get_civicrm_image() function in template.php at present?


fm

  • I post occasionally
  • **
  • Posts: 80
  • Karma: 1
Re: Custom data image, Drupal Views, Thumbnails?
March 12, 2010, 04:46:07 am
Code: [Select]
//This reads the CiviEvents image field ID and replaces it with its associated image file.
 
function get_civicrm_image($id, $dimensions=array(200,200)) {
civicrm_initialize();
require_once('api/File.php');

// get the file details
$file = crm_get_file(array('id'=>$id)); die(print_r($file, TRUE));
$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;
}

lentilsoup

  • I post frequently
  • ***
  • Posts: 134
  • Karma: 6
Re: Custom data image, Drupal Views, Thumbnails?
March 12, 2010, 07:36:55 am
Remove "die(print_r($file, TRUE));" from the get_civicrm_image() function.

fm

  • I post occasionally
  • **
  • Posts: 80
  • Karma: 1
Re: Custom data image, Drupal Views, Thumbnails?
March 12, 2010, 09:41:32 am
The change throws this error: 'warning: Division by zero in ~/includes/image.inc on line 160.'

In image.inc, line 160 is:

Code: [Select]
 $scale = max($width / $info['width'], $height / $info['height']);
This change also outputs something else in the block that looks encouraging: '/sites/<multi-site name>/files/civicrm/custom/_200x200'. Additionally, in Safari there is a missing-image icon beneath the text output. The filepath for the missing-image is the same as the text output. There is no '_200x200' directory; should I create that directory?

In Firefox, it's just the text output and no icon.

lentilsoup

  • I post frequently
  • ***
  • Posts: 134
  • Karma: 6
Re: Custom data image, Drupal Views, Thumbnails?
March 12, 2010, 09:47:26 am
I need you to figure out where in your directory structure CiviCRM is saving uploaded files.

Donald Lobo

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 15963
  • Karma: 470
    • CiviCRM site
  • CiviCRM version: 4.2+
  • CMS version: Drupal 7, Joomla 2.5+
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: Custom data image, Drupal Views, Thumbnails?
March 12, 2010, 09:53:12 am

u;ll might want to interact with each other on the CiviCRM IRC Channel: http://webchat.freenode.net/?channels=#civicrm

might make it easier to make progress with this

just my 2 cents :)

lobo

p.s> kinda nice to see the interaction between community folks :)
A new CiviCRM Q&A resource needs YOUR help to get started. Visit our StackExchange proposed site, sign up and vote on 5 questions

fm

  • I post occasionally
  • **
  • Posts: 80
  • Karma: 1
Re: Custom data image, Drupal Views, Thumbnails?
March 12, 2010, 09:55:29 am
it appears to be saving them to '/sites/<multi-site name>/files/civicrm/custom'

There is an image file in there that is labeled '_300x200' at the end of the file name, and its dimensions (at a glance) seem to be consistent with that. I'm pretty sure I didn't create that manually, so something was working at some point. :)

Also, good point, lobo.

lentilsoup

  • I post frequently
  • ***
  • Posts: 134
  • Karma: 6
Re: Custom data image, Drupal Views, Thumbnails?
March 12, 2010, 10:22:40 am
Quote from: Donald Lobo on March 12, 2010, 09:53:12 am
u;ll might want to interact with each other on the CiviCRM IRC Channel: http://webchat.freenode.net/?channels=#civicrm

THanks, lobo, that's a good idea.

I do like the asynchronicity of the forum, though.  ;)

fm, does the /sites/<multi-site name>/files/civicrm/custom directory contain the 72_dpi_Bosc_on_Box_edited_1_f3cf598b364fe47ea155995eddd67e49.jpg image?

fm

  • I post occasionally
  • **
  • Posts: 80
  • Karma: 1
Re: Custom data image, Drupal Views, Thumbnails?
March 12, 2010, 10:32:09 am
yes.

lentilsoup

  • I post frequently
  • ***
  • Posts: 134
  • Karma: 6
Re: Custom data image, Drupal Views, Thumbnails?
March 12, 2010, 10:50:31 am

After
Code: [Select]
$old_path = $root . '/' . file_directory_path() . '/civicrm/custom/' . $filename;
add:

Code: [Select]
if(file_exists($old_path)) { die('found file: ' . $old_path'); }
else { die('couldn't find file: ' . $old_path); }

fm

  • I post occasionally
  • **
  • Posts: 80
  • Karma: 1
Re: Custom data image, Drupal Views, Thumbnails?
March 12, 2010, 10:59:04 am
It's throwing an error: Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING in ~/sites/all/themes/blueprint/blueprint/template.php on line 543

Line 543 is:

Code: [Select]
else { die('could not find file: ' . $old_path); }
I changed "couldn't" to "could not" to avoid the extra apostrophe. The error above occurred both with and without the apostrophe.

lentilsoup

  • I post frequently
  • ***
  • Posts: 134
  • Karma: 6
Re: Custom data image, Drupal Views, Thumbnails?
March 12, 2010, 11:01:49 am
Typo on my part.  Remove the extra single quote after $old_path on the "if" line.

fm

  • I post occasionally
  • **
  • Posts: 80
  • Karma: 1
Re: Custom data image, Drupal Views, Thumbnails?
March 12, 2010, 11:07:05 am
Quotation mark removed.

The output is now: 'found file: ~/sites/<multi-site name>/files/civicrm/custom'

I also edited the line above the "if" line to omit parts of the filepath that were repeated. Prior to that the "file could not be found".

lentilsoup

  • I post frequently
  • ***
  • Posts: 134
  • Karma: 6
Re: Custom data image, Drupal Views, Thumbnails?
March 12, 2010, 11:12:07 am
And how does that line read now?

Pages: 1 ... 3 4 [5] 6 7
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM »
  • Using Drupal Modules (Moderator: Donald Lobo) »
  • Custom data image, Drupal Views, Thumbnails?

This forum was archived on 2017-11-26.