Issue 6477: Use the correct content-type to resize the images

This commit is contained in:
Michael 2019-06-20 20:09:33 +00:00
parent f0849b0a93
commit 14c28868eb
2 changed files with 10 additions and 8 deletions

View file

@ -1737,17 +1737,14 @@ class Contact extends BaseObject
$photos = Photo::importProfilePhoto($avatar, $uid, $cid, true); $photos = Photo::importProfilePhoto($avatar, $uid, $cid, true);
if ($photos) { if ($photos) {
DBA::update( $fields = ['avatar' => $avatar, 'photo' => $photos[0], 'thumb' => $photos[1], 'micro' => $photos[2], 'avatar-date' => DateTimeFormat::utcNow()];
'contact', DBA::update('contact', $fields, ['id' => $cid]);
['avatar' => $avatar, 'photo' => $photos[0], 'thumb' => $photos[1], 'micro' => $photos[2], 'avatar-date' => DateTimeFormat::utcNow()],
['id' => $cid]
);
// Update the public contact (contact id = 0) // Update the public contact (contact id = 0)
if ($uid != 0) { if ($uid != 0) {
$pcontact = DBA::selectFirst('contact', ['id'], ['nurl' => $contact['nurl'], 'uid' => 0]); $pcontact = DBA::selectFirst('contact', ['id'], ['nurl' => $contact['nurl'], 'uid' => 0]);
if (DBA::isResult($pcontact)) { if (DBA::isResult($pcontact)) {
self::updateAvatar($avatar, 0, $pcontact['id'], $force); DBA::update('contact', $fields, ['id' => $pcontact['id']]);
} }
} }

View file

@ -414,7 +414,9 @@ class Photo extends BaseObject
$filename = basename($image_url); $filename = basename($image_url);
if (!empty($image_url)) { if (!empty($image_url)) {
$img_str = Network::fetchUrl($image_url, true); $ret = Network::curl($image_url, true);
$img_str = $ret->getBody();
$type = $ret->getContentType();
} else { } else {
$img_str = ''; $img_str = '';
} }
@ -423,7 +425,10 @@ class Photo extends BaseObject
return false; return false;
} }
if (empty($type)) {
$type = Image::guessType($image_url, true); $type = Image::guessType($image_url, true);
}
$Image = new Image($img_str, $type); $Image = new Image($img_str, $type);
if ($Image->isValid()) { if ($Image->isValid()) {
$Image->scaleToSquare(300); $Image->scaleToSquare(300);