- } else {
-
- // save it as an avatar
- $profile = $user->getProfile();
-
- if ($profile->setOriginal($filename)) {
- common_log(
- LOG_INFO,
- sprintf(
- 'Saved avatar for %s (%d) from Facebook picture for '
- . '%s (fbuid %d), filename = %s',
- $user->nickname,
- $user->id,
- $this->fbuser['name'],
- $this->fbuid,
- $filename
- ),
- __FILE__
- );
+ if (!$ok) {
+ common_log(LOG_WARNING, 'Couldn\'t save tmp Facebook avatar: ' . $tmpname, __FILE__);
+ } else {
+ // save it as an avatar
+
+ $imagefile = new ImageFile(null, Avatar::path($tmpname));
+ $filename = Avatar::filename($user->id, image_type_to_extension($imagefile->preferredType()),
+ 180, common_timestamp());
+ // Previous docs said 180 is the "biggest img we get from Facebook"
+ $imagefile->resizeTo(Avatar::path($filename, array('width'=>180, 'height'=>180)));
+
+ // No need to keep the temporary file around...
+ @unlink(Avatar::path($tmpname));
+
+ $profile = $user->getProfile();
+
+ if ($profile->setOriginal($filename)) {
+ common_log(
+ LOG_INFO,
+ sprintf(
+ 'Saved avatar for %s (%d) from Facebook picture for '
+ . '%s (fbuid %d), filename = %s',
+ $user->nickname,
+ $user->id,
+ $this->fbuser->name,
+ $this->fbuid,
+ $filename
+ ),
+ __FILE__
+ );
+
+ // clean up tmp file
+ }
+