diff -Naur ldapdev/ldap_servers/LdapServerAdmin.class.php ldapdevpatch/ldap_servers/LdapServerAdmin.class.php
--- ldapdev/ldap_servers/LdapServerAdmin.class.php	2013-02-11 02:00:09.000000000 +0100
+++ ldapdevpatch/ldap_servers/LdapServerAdmin.class.php	2013-02-12 10:42:37.000000000 +0100
@@ -66,8 +66,10 @@
     $this->user_dn_expression = trim($values['user_dn_expression']);
     $this->basedn = $this->linesToArray(trim($values['basedn']));
     $this->user_attr = drupal_strtolower(trim($values['user_attr']));
+    $this->picture_attr = drupal_strtolower(trim($values['picture_attr']));
     $this->account_name_attr = drupal_strtolower(trim($values['account_name_attr']));
     $this->mail_attr = drupal_strtolower(trim($values['mail_attr']));
+    $this->picture_attr = drupal_strtolower(trim($values['picture_attr']));
     $this->mail_template = trim($values['mail_template']);
     $this->unique_persistent_attr = drupal_strtolower(trim($values['unique_persistent_attr']));
     $this->unique_persistent_attr_binary = trim($values['unique_persistent_attr_binary']);
@@ -93,6 +95,7 @@
 
     $this->searchPagination = ($values['search_pagination']) ? 1 : 0;
     $this->searchPageSize = trim($values['search_page_size']);
+    
 
   }
 
@@ -514,6 +517,7 @@
      * consumer_type is tag (unique alphanumeric id) of consuming authorization such as
      *   drupal_roles, og_groups, civicrm_memberships
      */
+  	
     $fields = array(
 
       'sid' => array(
@@ -787,6 +791,21 @@
           'not null' => FALSE,
         ),
       ),
+      
+      'picture_attr' => array(
+      		'form' => array(
+      				'fieldset' => 'users',
+      				'#type' => 'textfield',
+      				'#size' => 30,
+      				'#title' => t('Thumbnail attribute'),
+      				'#description' => t('The attribute that holds the users\' thumnail image. (eg. <code>thumbnailPhoto</code>). Leave empty if no such attribute exists'),
+      		),
+      		'schema' => array(
+      				'type' => 'varchar',
+      				'length' => 255,
+      				'not null' => FALSE,
+      		),
+      ),
 
       'mail_template' => array(
         'form' => array(
diff -Naur ldapdev/ldap_servers/LdapServer.class.php ldapdevpatch/ldap_servers/LdapServer.class.php
--- ldapdev/ldap_servers/LdapServer.class.php	2013-02-11 02:00:09.000000000 +0100
+++ ldapdevpatch/ldap_servers/LdapServer.class.php	2013-02-12 13:56:04.000000000 +0100
@@ -36,6 +36,7 @@
   public $bindpw = FALSE; // Default to an anonymous bind.
   public $user_dn_expression;
   public $user_attr;
+	public $picture_attr;
   public $account_name_attr; //lowercase
   public $mail_attr; //lowercase
   public $mail_template;
@@ -100,6 +101,7 @@
     'user_attr'  => 'user_attr',
     'account_name_attr'  => 'account_name_attr',
     'mail_attr'  => 'mail_attr',
+				'picture_attr'  => 'picture_attr',
     'mail_template'  => 'mail_template',
     'unique_persistent_attr' => 'unique_persistent_attr',
     'unique_persistent_attr_binary' => 'unique_persistent_attr_binary',
@@ -648,7 +650,7 @@
       * -- http://sgehrig.wordpress.com/2009/11/06/reading-paged-ldap-results-with-php-is-a-show-stopper/
       */
 
-
+		$filter = strtolower($filter);
     if ($base_dn == NULL) {
       if (count($this->basedn) == 1) {
         $base_dn = $this->basedn[0];
@@ -996,6 +998,71 @@
     }
   }
 
+	/**
+	 * @param ldap entry array $ldap_entry
+	 *
+	 * @return drupal file object image user's thumbnail or FALSE if none present or ERROR happens.
+	 */
+	public function userPictureFromLdapEntry($ldap_entry) {
+		if ($ldap_entry && $this->picture_attr) {
+			//Check if ldap entry has been provisioned.
+			$account = user_load_by_name($ldap_entry[$this->user_attr][0]);						
+			$thumb = isset($ldap_entry[$this->picture_attr][0]) ? $ldap_entry[$this->picture_attr][0] : FALSE;
+			if(!$thumb || $account->uid == '0'){
+				return false;
+			}
+			//Create md5 check.						
+			$md5thumb = md5($thumb);
+			/**
+			 * If account already has picture check if it has changed if so remove old file and create the new one 
+			 * If picture is not set but account has md5 something is wrong exit. 
+			 */
+			
+			if(isset($account->picture)){
+				// Check if image has changed
+				if(isset($account->data['ldap_user']['init']['thumb5md']) && $md5thumb === $account->data['ldap_user']['init']['thumb5md']){
+					//No change return same image					
+					return $account->picture;					
+				}else{
+					//Image is different check wether is obj/str and remove fileobject
+					if(is_object($account->picture)){
+						file_delete($account->picture, TRUE);
+					}else if(is_string($account->picture)){
+						$file = file_load(intval($account->picture));
+						file_delete($file, TRUE);
+					}
+				}			
+			}else if(isset($account->data['ldap_user']['init']['thumb5md'])) {
+				watchdog('ldap_server', "Some error happened during thumbnailPhoto sync");
+				return false;
+			}
+			//Create tmp file to get image format.
+			$filename = uniqid();
+			$fileuri = file_directory_temp() .'/'. $filename;
+			$size = file_put_contents($fileuri, $thumb);				
+			$info = image_get_info($fileuri);
+			unlink($fileuri);
+			// create file object
+			$file = file_save_data($thumb, 'public://' . variable_get('user_picture_path') .'/'. $filename .'.'. $info['extension']);
+			$file->md5Sum = $md5thumb;
+			// standard Drupal validators for user pictures
+			$validators = array(
+					'file_validate_is_image' => array(),
+					'file_validate_image_resolution' => array(variable_get('user_picture_dimensions', '85x85')),
+					'file_validate_size' => array(variable_get('user_picture_file_size', '30') * 1024),
+			);
+			$errors = file_validate($file ,$validators);
+			if (empty($errors)) {
+				return $file;
+			}else{
+				foreach($errors as $err => $err_val){
+					watchdog('ldap_server', "Error storing picture: %$err", "%$err_val", WATCHDOG_ERROR );
+				}
+				return false;
+			}
+		}
+	}
+	
 
   /**
    * @param ldap entry array $ldap_entry
diff -Naur ldapdev/ldap_servers/ldap_servers.install ldapdevpatch/ldap_servers/ldap_servers.install
--- ldapdev/ldap_servers/ldap_servers.install	2013-02-11 02:00:09.000000000 +0100
+++ ldapdevpatch/ldap_servers/ldap_servers.install	2013-02-12 10:35:03.000000000 +0100
@@ -763,6 +763,22 @@
 
 }
 
+/**
+ * Add picture_attr field in schema
+ * 
+ * 
+ */
+function ldap_servers_update_7204() {
+	db_add_field(
+			'ldap_servers',			
+			'picture_attr',
+			array(
+					'type' => 'varchar',
+					'length' => 255,
+					'not null' => FALSE,
+			)
+	);		
+}
 
 function ldap_servers_install_update_schema($schema, &$change_log) {
   foreach ($schema as $table_name => $table_schema) {
diff -Naur ldapdev/ldap_servers/ldap_servers.module ldapdevpatch/ldap_servers/ldap_servers.module
--- ldapdev/ldap_servers/ldap_servers.module	2013-02-11 02:00:09.000000000 +0100
+++ ldapdevpatch/ldap_servers/ldap_servers.module	2013-02-12 10:37:08.000000000 +0100
@@ -326,6 +326,9 @@
       if ($ldap_server->mail_template) {
         ldap_servers_token_extract_attributes($attributes, $ldap_server->mail_template);
       }
+      if(!isset($attributes[$ldap_server->picture_attr])){
+      	$attributes[$ldap_server->picture_attr] = ldap_servers_set_attribute_map();
+      }
       if (!isset($attributes[$ldap_server->user_attr])) {
         $attributes[$ldap_server->user_attr] = ldap_servers_set_attribute_map();
       }
@@ -456,6 +459,20 @@
         'config_module' => 'ldap_server',
         'prov_module' => 'ldap_user',
       ) + $available_user_attrs['[property.mail]'];
+      
+      if (!isset($available_user_attrs['[property.picture]']) || !is_array($available_user_attrs['[property.picture]'])) {
+      	$available_user_attrs['[property.picture]'] = array();
+      }
+      $available_user_attrs['[property.picture]'] = array(
+      		'name' => 'Property: Picture',
+      		'source' => '[' . $ldap_server->picture_attr . ']',
+      		'direction' => LDAP_USER_PROV_DIRECTION_TO_DRUPAL_USER,
+      		'enabled' => TRUE,
+      		'prov_events' => array(LDAP_USER_EVENT_CREATE_DRUPAL_USER, LDAP_USER_EVENT_SYNCH_TO_DRUPAL_USER),
+      		'config_module' => 'ldap_server',
+      		'prov_module' => 'ldap_user',
+      ) + $available_user_attrs['[property.picture]'];
+      
     }
   }
  // debug('available_user_attrs2'); debug($available_user_attrs);
diff -Naur ldapdev/ldap_user/LdapUserConf.class.php ldapdevpatch/ldap_user/LdapUserConf.class.php
--- ldapdev/ldap_user/LdapUserConf.class.php	2013-02-11 02:00:09.000000000 +0100
+++ ldapdevpatch/ldap_user/LdapUserConf.class.php	2013-02-12 10:50:13.000000000 +0100
@@ -1194,8 +1194,18 @@
       $derived_mail = $ldap_server->userEmailFromLdapEntry($ldap_user['attr']);
       if ($derived_mail) {
         $edit['mail'] = $derived_mail;
-      }
-    }
+			}
+		}
+		//Load picture
+		if ($this->isSynched('[property.picture]', $prov_events, $direction) && !isset($edit['name'])){
+			$picture = $ldap_server->userPictureFromLdapEntry($ldap_user['attr']);
+			if($picture){
+				$edit['picture'] = $picture;
+				if(isset($picture->md5Sum)){
+					$edit['data']['ldap_user']['init']['thumb5md'] = $picture->md5Sum;
+				}				
+			}
+		}
 
     if ($this->isSynched('[property.name]', $prov_events, $direction) && !isset($edit['name'])) {
       $name = $ldap_server->userUsernameFromLdapEntry($ldap_user['attr']);
@@ -1206,6 +1216,7 @@
 
     if ($direction == LDAP_USER_PROV_DIRECTION_TO_DRUPAL_USER && in_array(LDAP_USER_EVENT_CREATE_DRUPAL_USER, $prov_events)) {
       $edit['mail'] = isset($edit['mail']) ? $edit['mail'] : $ldap_user['mail'];
+			$edit['picture'] = isset($edit['picture']) ? $edit['picture'] : $ldap_user['picture'];
       $edit['pass'] = isset($edit['pass']) ? $edit['pass'] : user_password(20);
       $edit['init'] = isset($edit['init']) ? $edit['init'] : $edit['mail'];
       $edit['status'] = isset($edit['status']) ? $edit['status'] : 1;
diff -Naur ldapdev/ldap_user/ldap_user.module ldapdevpatch/ldap_user/ldap_user.module
--- ldapdev/ldap_user/ldap_user.module	2013-02-11 02:00:09.000000000 +0100
+++ ldapdevpatch/ldap_user/ldap_user.module	2013-02-12 10:45:41.000000000 +0100
@@ -60,6 +60,7 @@
 define('LDAP_USER_TEST_FORM_PATH', 'admin/config/people/ldap/user/test');
 define('LDAP_USER_WS_USER_PATH', 'ldap/user/ws');
 
+
 /**
  * Implements hook_menu().
  */
@@ -223,6 +224,7 @@
       case 'ldap_user_ldap_associate':
         $attributes[$ldap_server->user_attr] = ldap_servers_set_attribute_map(@$attributes[$ldap_server->user_attr]); // array($ldap_server->user_attr, 0, NULL);
         $attributes[$ldap_server->mail_attr] = ldap_servers_set_attribute_map(@$attributes[$ldap_server->mail_attr]);
+        $attributes[$ldap_server->picture_attr] = ldap_servers_set_attribute_map(@$attributes[$ldap_server->picture_attr]);
         $attributes[$ldap_server->unique_persistent_attr] = ldap_servers_set_attribute_map(@$attributes[$ldap_server->unique_persistent_attr]);
         if ($ldap_server->mail_template) {
           ldap_servers_token_extract_attributes($attributes,  $ldap_server->mail_template);
@@ -270,6 +272,18 @@
       'prov_module' => 'ldap_user',
       'configurable_to_ldap' => TRUE,
     );
+    
+    $available_user_attrs['[property.picture]'] =  array(
+    		'name' => 'Property: picture',
+    		'source' => '',
+    		'direction' => LDAP_USER_PROV_DIRECTION_TO_LDAP_ENTRY,
+    		'enabled' => TRUE,
+    		'prov_events' => array(LDAP_USER_EVENT_CREATE_LDAP_ENTRY, LDAP_USER_EVENT_SYNCH_TO_LDAP_ENTRY),
+    		'config_module' => 'ldap_user',
+    		'prov_module' => 'ldap_user',
+    		'configurable_to_ldap' => TRUE,
+    );
+    
 
     $available_user_attrs['[property.uid]'] =  array(
       'name' => 'Property: Drupal User Id (uid)',
@@ -342,6 +356,7 @@
   if (!$ldap_user_conf->provisionsDrupalAccountsFromLdap) {
     $available_user_attrs['[property.mail]']['config_module'] = 'ldap_user';
     $available_user_attrs['[property.name]']['config_module'] = 'ldap_user';
+    $available_user_attrs['[property.picture]']['config_module'] = 'ldap_user';
   }
 
   if ($direction == LDAP_USER_PROV_DIRECTION_TO_LDAP_ENTRY) {
@@ -473,8 +488,6 @@
 }
 
 
-
-
 /**
  * Implements hook_form_FORM_ID_alter(). for user_register_form
  */
@@ -812,12 +825,14 @@
   $prov_enabled = $ldap_user_conf->provisionEnabled(LDAP_USER_PROV_DIRECTION_TO_DRUPAL_USER, LDAP_USER_LDAP_ENTRY_PROV_ON_AUTHENTICATE);
 
   if ($ldap_user_conf->provisionsDrupalAccountsFromLdap && in_array(LDAP_USER_EVENT_SYNCH_TO_DRUPAL_USER, array_keys($ldap_user_conf->provisionsDrupalEvents))) {
-    $ldap_user = ldap_servers_get_user_ldap_data($account->name, $ldap_user_conf->drupalAcctProvisionServer, 'ldap_user_prov_to_drupal');
+    $ldap_user = ldap_servers_get_user_ldap_data($account->name, $ldap_user_conf->drupalAcctProvisionServer, 'ldap_user_prov_to_drupal');    
     if ($ldap_user) {
       $ldap_server = ldap_servers_get_servers($ldap_user_conf->drupalAcctProvisionServer, NULL, TRUE);
       $ldap_user_conf->entryToUserEdit($ldap_user, $user_edit, $ldap_server, LDAP_USER_PROV_DIRECTION_TO_DRUPAL_USER, array(LDAP_USER_EVENT_SYNCH_TO_DRUPAL_USER));
     }
     $account = user_save($account, $user_edit, 'ldap_user');
+    
+	 
   }
 
 }
@@ -926,8 +941,9 @@
     if (ldap_user_is_ldap_associated($account, LDAP_USER_PROV_DIRECTION_TO_DRUPAL_USER)) {
       $ldap_user = ldap_servers_get_user_ldap_data($account->name, $ldap_user_conf->drupalAcctProvisionServer, 'ldap_user_prov_to_drupal');
       $ldap_server = ldap_servers_get_servers($ldap_user_conf->drupalAcctProvisionServer, NULL, TRUE);
-      $ldap_user_conf->entryToUserEdit($ldap_user, $user_edit, $ldap_server, LDAP_USER_PROV_DIRECTION_TO_DRUPAL_USER, array(LDAP_USER_EVENT_SYNCH_TO_DRUPAL_USER));
+      $ldap_user_conf->entryToUserEdit($ldap_user, $user_edit, $ldap_server, LDAP_USER_PROV_DIRECTION_TO_DRUPAL_USER, array(LDAP_USER_EVENT_SYNCH_TO_DRUPAL_USER));            
       $account = user_save($account, $user_edit, 'ldap_user');
+          
     }
   }
 
