From: Michael <heluecht@pirati.ca>
Date: Thu, 20 Jun 2019 20:09:33 +0000 (+0000)
Subject: Issue 6477: Use the correct content-type to resize the images
X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=14c28868eb8ee17f0e9e742f73a10786f2591a76;p=friendica.git

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

diff --git a/src/Model/Contact.php b/src/Model/Contact.php
index 9e3f2a15de..a6026d6440 100644
--- a/src/Model/Contact.php
+++ b/src/Model/Contact.php
@@ -1737,17 +1737,14 @@ class Contact extends BaseObject
 			$photos = Photo::importProfilePhoto($avatar, $uid, $cid, true);
 
 			if ($photos) {
-				DBA::update(
-					'contact',
-					['avatar' => $avatar, 'photo' => $photos[0], 'thumb' => $photos[1], 'micro' => $photos[2], 'avatar-date' => DateTimeFormat::utcNow()],
-					['id' => $cid]
-				);
+				$fields = ['avatar' => $avatar, 'photo' => $photos[0], 'thumb' => $photos[1], 'micro' => $photos[2], 'avatar-date' => DateTimeFormat::utcNow()];
+				DBA::update('contact', $fields, ['id' => $cid]);
 
 				// Update the public contact (contact id = 0)
 				if ($uid != 0) {
 					$pcontact = DBA::selectFirst('contact', ['id'], ['nurl' => $contact['nurl'], 'uid' => 0]);
 					if (DBA::isResult($pcontact)) {
-						self::updateAvatar($avatar, 0, $pcontact['id'], $force);
+						DBA::update('contact', $fields, ['id' => $pcontact['id']]);
 					}
 				}
 
diff --git a/src/Model/Photo.php b/src/Model/Photo.php
index 2d740e1378..68665126fb 100644
--- a/src/Model/Photo.php
+++ b/src/Model/Photo.php
@@ -414,7 +414,9 @@ class Photo extends BaseObject
 
 		$filename = basename($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 {
 			$img_str = '';
 		}
@@ -423,7 +425,10 @@ class Photo extends BaseObject
 			return false;
 		}
 
-		$type = Image::guessType($image_url, true);
+		if (empty($type)) {
+			$type = Image::guessType($image_url, true);
+		}
+
 		$Image = new Image($img_str, $type);
 		if ($Image->isValid()) {
 			$Image->scaleToSquare(300);