Answers.Body: <p>Your site is affected by <a href="https://issues.civicrm.org/jira/browse/CRM-16009" rel="nofollow">CRM-16009 - URL for Contact Image in View incorrectly generating</a>.</p>
  
  <p>That URL should look like this -</p>
  
  <pre><code>http://example.com/civicrm/contact/imagefile?photo=mbd_logo_01cf3f5560578c6554b9ba009f6b42b7.png
  </code></pre>
  
  <p>rather than this -</p>
  
  <pre><code>http://example.com/sites/example.com/files/example.com/civicrm/contact/imagefile%3Fphoto%3Dmbd_logo_01cf3f5560578c6554b9ba009f6b42b7.png
  </code></pre>
  
  <p>The <code>civicrm/contact/imagefile</code> handler permits CiviCRM to provide its permissions checks on whether the image in question should be served up. </p>
  
  <p>Since that code was merged, there's a good chance it worked for someone and this may be fixable in configuration. It looks like the URLs you're getting from Views are confused - possibly by CiviCRM configuration, or by an issue with the views implementation as it currently stands, possibly an incorrect assumption in code about the location of CiviCRM codebase or system files, etc.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-04-08T03:49:30.083Z
Answers.Text: See [these notes](https://gist.github.com/xurizaemon/795696d1e8b25b8b9130) and [this forum thread](http://forum.civicrm.org/index.php/topic,34929.msg151830.html#msg151830) for some notes / performance metrics based on current CiviCRM.org use of the imagefile handler.
Answers.UserDisplayName: Chris Burgess
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-04-08T14:26:09.540Z
Answers.Text: Thanks @Chris Burgess for the detailed explanation, advice, and links to resources. I agree with you that serving images publicly via CiviCRM is not ideal in terms of performance. However in my use-case it *is* ideal in terms of simplicity and usability: my view shows the logos of "active sponsors" (organizations with current/active memberships). From a data entry perspective they can just pull up the contact, add the logo, record the membership. The logo then appears in the view automatically. When the membership expires, the views filter removes the logo. When they renew, the logo reappears.
Answers.UserDisplayName: LunkRat
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-04-08T20:38:44.907Z
Answers.Text: Great to see you're engaging that issue Link.
  
  Yep, understood about convenience of the CiviCRM field. To clarify: once set up, using ImageCache External in front of the active sponsor images would give you the same behaviour (the styled image would appear in the view conditional on sponsorship) but you'd have a faster-loading site. Whether it's worth the effort depends on your traffic and resources!
Answers.UserDisplayName: Chris Burgess
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-04-08T20:50:45.730Z
Answers.Text: Yep, I understand and I definitely plan to look into imagecache_external. I'm also looking at https://github.com/civicrm/civicrm-drupal/blob/7.x-master/modules/views/civicrm/civicrm_handler_field_contact_image.inc#L137-L203 to see if I can spot and fix the malformed URL issues. Or maybe some other rockstar Drupal PHP wizards will read this and click the above link and pinpoint the problem?
Answers.UserDisplayName: LunkRat
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-08-07T20:25:58.757Z
Answers.Text: It seems that in 4.6.6 the contact image is completely broken if I choose a Drupal image preset, it outputs: ```<img typeof="foaf:Image" src="http://styles/medium/http/example.org/civicrm/contact/imagefile?photo=bsglogo_49524b829beb4448767ee75a42f2dcc0.jpg&amp;itok=dGLXdcig" width="220" height="220" alt="" title="">```
Answers.UserDisplayName: LunkRat
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-04-08T03:49:25.530Z
Answers.Text: Serving images from CiviCRM file fields also incurs a substantial performance kick; I recommend not using CiviCRM imagefile fields if you are serving images to the public. You're far better off serving the file directly with no PHP at all OR putting ImageCache + [ImageCache External](https://www.drupal.org/project/imagecache_external) in front of it. Initialising CiviCRM for each image request adds some real delay to the process.
Answers.UserDisplayName: Chris Burgess
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-04-08T03:22:40.990Z
Answers.LastActivityDate: 2015-04-08T03:48:11.667Z
Answers.LastEditDate: 2015-04-08T03:48:11.667Z
Answers.UserDisplayName: Chris Burgess
Body: <p>Just upgraded to 4.6.0 and now I see that the <code>CiviCRM Contact Image</code> field in Drupal views <a href="https://issues.civicrm.org/jira/browse/CRM-14491" rel="nofollow noreferrer">now uses the views image handler</a>! Awesome! Prior to 4.6 it was just a string containing a URL to the image. Thanks to <a href="https://civicrm.stackexchange.com/users/69/shawn-duncan">@Shawn Duncan</a> for his efforts and <a href="https://github.com/civicrm/civicrm-drupal/pull/140/files" rel="nofollow noreferrer">contribution</a>.</p>
  <p>However, I can't get it to work. The image URL it produces gives a <code>404</code></p>
  <p>Example URL that returns 404:</p>
  <p><code>http://example.com/sites/example.com/files/example.com/civicrm/contact/imagefile%3Fphoto%3Dmbd_logo_01cf3f5560578c6554b9ba009f6b42b7.png</code></p>
  <p>But the actual working URL to the file is:</p>
  <p><code>http://example.com/sites/example.com/files/civicrm/custom/mbd_logo_01cf3f5560578c6554b9ba009f6b42b7.png</code></p>
  <p>So it's inserting an extra <code>example.com</code> after the <code>/files/</code> and it's using this <code>/contact/imagefile%3Fphoto%3D</code> instead of the actual path to my custom uploads.</p>
  <hr />
  <p>[Edit]</p>
  <p>Using Drupal image presets is broken in 4.6 since at least 4.6.6; if you select an image style in Views, it mangles the URL to something like</p>
  <p><code>&lt;img typeof=&quot;foaf:Image&quot; src=&quot;http://styles/medium/http/example.org/civicrm/contact/imagefile?photo=bsglo‌​go_49524b829beb4448767ee75a42f2dcc0.jpg&amp;amp;itok=dGLXdcig&quot; width=&quot;220&quot; height=&quot;220&quot; alt=&quot;&quot; title=&quot;&quot;&gt;</code></p>
  <p>Is there a suitable workaround?</p>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2015-04-08T02:28:40.663Z
Comments.Text: I have edited my question to include links to the relevant issue tracker page and GitHub pull request.
Comments.UserDisplayName: LunkRat
Tags: <drupal><drupal-views><4.6><contact-image>
Title: How do I fix error with the new (4.6.0) Drupal views image handler for CiviCRM contact images
ThreadText: # How do I fix error with the new (4.6.0) Drupal views image handler for CiviCRM contact images
  
  (Asked by: username_0 on 2015-04-07)
  
  Just upgraded to 4.6.0 and now I see that the `CiviCRM Contact Image` field in Drupal views [now uses the views image handler](https://issues.civicrm.org/jira/browse/CRM-14491)! Awesome! Prior to 4.6 it was just a string containing a URL to the image. Thanks to [@Shawn Duncan](https://civicrm.stackexchange.com/users/69/shawn-duncan) for his efforts and [contribution](https://github.com/civicrm/civicrm-drupal/pull/140/files).
  
  However, I can't get it to work. The image URL it produces gives a `404`
  
  Example URL that returns 404:
  
  `http://example.com/sites/example.com/files/example.com/civicrm/contact/imagefile%3Fphoto%3Dmbd_logo_01cf3f5560578c6554b9ba009f6b42b7.png`
  
  But the actual working URL to the file is:
  
  `http://example.com/sites/example.com/files/civicrm/custom/mbd_logo_01cf3f5560578c6554b9ba009f6b42b7.png`
  
  So it's inserting an extra `example.com` after the `/files/` and it's using this `/contact/imagefile%3Fphoto%3D` instead of the actual path to my custom uploads.
  
  ---
  
  [Edit]
  
  Using Drupal image presets is broken in 4.6 since at least 4.6.6; if you select an image style in Views, it mangles the URL to something like
  
  `<img typeof="foaf:Image" src="http://styles/medium/http/example.org/civicrm/contact/imagefile?photo=bsglo‌​go_49524b829beb4448767ee75a42f2dcc0.jpg&amp;itok=dGLXdcig" width="220" height="220" alt="" title="">`
  
  Is there a suitable workaround?
  
  **Tags:** drupal, drupal-views, 4.6, contact-image
  
  > **Comments:**
  > **username_0**: I have edited my question to include links to the relevant issue tracker page and GitHub pull request.  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2015-04-08. Score: 3 | Accepted answer
  
  Your site is affected by [CRM-16009 - URL for Contact Image in View incorrectly generating](https://issues.civicrm.org/jira/browse/CRM-16009).
  
  That URL should look like this -
  
  ```
  http://example.com/civicrm/contact/imagefile?photo=mbd_logo_01cf3f5560578c6554b9ba009f6b42b7.png
  
  ```
  
  rather than this -
  
  ```
  http://example.com/sites/example.com/files/example.com/civicrm/contact/imagefile%3Fphoto%3Dmbd_logo_01cf3f5560578c6554b9ba009f6b42b7.png
  
  ```
  
  The `civicrm/contact/imagefile` handler permits CiviCRM to provide its permissions checks on whether the image in question should be served up.
  
  Since that code was merged, there's a good chance it worked for someone and this may be fixable in configuration. It looks like the URLs you're getting from Views are confused - possibly by CiviCRM configuration, or by an issue with the views implementation as it currently stands, possibly an incorrect assumption in code about the location of CiviCRM codebase or system files, etc.
  
  > **Comments:**
  > **username_1**: Serving images from CiviCRM file fields also incurs a substantial performance kick; I recommend not using CiviCRM imagefile fields if you are serving images to the public. You're far better off serving the file directly with no PHP at all OR putting ImageCache + [ImageCache External](https://www.drupal.org/project/imagecache_external) in front of it. Initialising CiviCRM for each image request adds some real delay to the process.  
  > **username_1**: See [these notes](https://gist.github.com/xurizaemon/795696d1e8b25b8b9130) and [this forum thread](http://forum.civicrm.org/index.php/topic,34929.msg151830.html#msg151830) for some notes / performance metrics based on current CiviCRM.org use of the imagefile handler.  
  > **username_0**: Thanks @username_1 for the detailed explanation, advice, and links to resources. I agree with you that serving images publicly via CiviCRM is not ideal in terms of performance. However in my use-case it *is* ideal in terms of simplicity and usability: my view shows the logos of "active sponsors" (organizations with current/active memberships). From a data entry perspective they can just pull up the contact, add the logo, record the membership. The logo then appears in the view automatically. When the membership expires, the views filter removes the logo. When they renew, the logo reappears.  
  > **username_1**: Great to see you're engaging that issue Link.  Yep, understood about convenience of the CiviCRM field. To clarify: once set up, using ImageCache External in front of the active sponsor images would give you the same behaviour (the styled image would appear in the view conditional on sponsorship) but you'd have a faster-loading site. Whether it's worth the effort depends on your traffic and resources!  
  > **username_0**: Yep, I understand and I definitely plan to look into imagecache_external. I'm also looking at https://github.com/civicrm/civicrm-drupal/blob/7.x-master/modules/views/civicrm/civicrm_handler_field_contact_image.inc#L137-L203 to see if I can spot and fix the malformed URL issues. Or maybe some other rockstar Drupal PHP wizards will read this and click the above link and pinpoint the problem?  
  > **username_0**: It seems that in 4.6.6 the contact image is completely broken if I choose a Drupal image preset, it outputs: ```<img typeof="foaf:Image" src="http://styles/medium/http/example.org/civicrm/contact/imagefile?photo=bsglogo_49524b829beb4448767ee75a42f2dcc0.jpg&amp;itok=dGLXdcig" width="220" height="220" alt="" title="">```  
  
  ---
  
  