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 Core CiviCRM Functions (Moderator: Yashodha Chaku) »
  • Contact Image width and height not retrieved on Prod. Server - Test Server works
Pages: [1]

Author Topic: Contact Image width and height not retrieved on Prod. Server - Test Server works  (Read 1216 times)

Alex Sondy

  • I’m new here
  • *
  • Posts: 21
  • Karma: 0
  • CiviCRM version: 4.0.7
  • CMS version: Drupal 7.2
  • MySQL version: 5.0.7
  • PHP version: 5.3.5
Contact Image width and height not retrieved on Prod. Server - Test Server works
January 05, 2012, 05:13:23 pm
Hello everyone,

I experience a weird behavior with the contact image. I changed the thumbnail calculation on the test server for the summary page to be always 200px hight and scale the width according to the $imageRatio. There it works flawless.

CRM/Contact/BAO/Contact.php Line 823
Code: [Select]
    public static function getThumbSize( $imageWidth, $imageHeight )
    {
// Adjust $thumbWidth
        $thumbWidth = 300;
$thumbHeight = 200;
// Adjust $thumbWidth end
        if ( $imageWidth && $imageHeight ) {
            $imageRatio = $imageWidth / $imageHeight ;
        } else {
            $imageRatio = 1;
        }
        if ( $imageRatio > 1 ) {
            $imageThumbWidth = $thumbWidth;
            $imageThumbHeight = round( $thumbWidth / $imageRatio );
        } else {
            $imageThumbHeight = $thumbHeight;
            $imageThumbWidth = round( $thumbHeight * $imageRatio );
        }
 
        return array( $imageThumbWidth, $imageThumbHeight ); 
    }

Weeks ago we moved to production server and just now I realized that all the contact image thumbnails are 200 x 200, caused by the fact that the $imageWidth and $imageHeight is not retrieved from the original image. Still, on the test server it works - online not.
???

I googled a hell lot and I found some hints that maybe the URL settings arren't right. However, those are the Settings:

Upload Directories:
Code: [Select]
/var/www/web2/html/cms/sites/default/files/civicrm/custom/
Image Upload URL:
Code: [Select]
http://pimandcems.de/sites/default/files/civicrm/custom/
The Image is correctly linked - just the width and hight information not parsed.

Any idea how to solve this on our production server?

Thank you!

Alex Sondy

  • I’m new here
  • *
  • Posts: 21
  • Karma: 0
  • CiviCRM version: 4.0.7
  • CMS version: Drupal 7.2
  • MySQL version: 5.0.7
  • PHP version: 5.3.5
Re: Contact Image width and height not retrieved on Prod. Server - Test Server works
January 05, 2012, 06:37:40 pm
Ok - I figured out what the Problem is.

The php function:
Code: [Select]
getimagesize( $image_URL );is not allowed to take the image url like this http://domain.com/sites/default/files/civicrm/custom/myimage.jpg - so the function can't get the width and hight.

I googled a little bit and operantly this is a scraping protection - the function works fine if the image is retrieved from the root URL:
/var/www/web2/html/cms/sites/default/files/civicrm/custom/myimage.jpg

I just modified for now CRM/Contact/Page/Views.php Line 152 to:
Code: [Select]
@ line 152  if ( isset( $config->enableSSL ) && $config->enableSSL ) {
                $image_URL = str_replace( 'http://', 'https://', $image_URL );   
            }

+          require_once 'CRM/Utils/System/Drupal.php';
+          $rootPath = CRM_Utils_System_Drupal::cmsRootPath( );
+          $customFileUploadDir = $config->customFileUploadDir;
+          $resource_image_URL = $customFileUploadDir . substr(strrchr($image_URL, '/'), 1);
+          list( $imageWidth, $imageHeight ) = getimagesize( $resource_image_URL );

-           list( $imageWidth, $imageHeight ) = getimagesize( $image_URL );

            list( $imageThumbWidth, $imageThumbHeight ) = CRM_Contact_BAO_Contact::getThumbSize( $imageWidth, $imageHeight );

This of course only works if the Upload Directories and the Image Upload URL point to the same folder.

The issue still persists everywhere else then the Contact Dashboard when using getimagesize. I'm not sure if I should file an issue - but if other hoster have the use of getimagesize limited as well, it might be a good idea to switch images over to internal referencing.

This all explains why it was working fine on the less protected testing server.

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM »
  • Using Core CiviCRM Functions (Moderator: Yashodha Chaku) »
  • Contact Image width and height not retrieved on Prod. Server - Test Server works

This forum was archived on 2017-11-26.