X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FModel%2FPhoto.php;h=82b8bd9dda3867615d146b5701de32df20b1736b;hb=6e31b8d6a54dca2f345aef961539ddae904c0395;hp=126bc152b4ddf2d9ce5d275e73c6a94a4327f1bc;hpb=2baa56d4787ebdb4a3b8f2a0b9e35d083333c922;p=friendica.git diff --git a/src/Model/Photo.php b/src/Model/Photo.php index 126bc152b4..82b8bd9dda 100644 --- a/src/Model/Photo.php +++ b/src/Model/Photo.php @@ -313,6 +313,28 @@ class Photo return $fields; } + /** + * Construct a photo array for a given image data string + * + * @param string $image_data Image data + * @param string $mimetype Image mime type. Is guessed by file name when empty. + * + * @return array + * @throws \Exception + */ + public static function createPhotoForImageData(string $image_data, string $mimetype = ''): array + { + $fields = self::getFields(); + $values = array_fill(0, count($fields), ''); + + $photo = array_combine($fields, $values); + $photo['data'] = $image_data; + $photo['type'] = $mimetype ?: Images::getMimeTypeByData($image_data); + $photo['cacheable'] = false; + + return $photo; + } + /** * Construct a photo array for a system resource image * @@ -346,11 +368,14 @@ class Photo * @param string $url Image URL * @param int $uid User ID of the requesting person * @param string $mimetype Image mime type. Is guessed by file name when empty. + * @param string $blurhash The blurhash that will be used to generate a picture when the original picture can't be fetched + * @param int $width Image width + * @param int $height Image height * * @return array * @throws \Exception */ - public static function createPhotoForExternalResource(string $url, int $uid = 0, string $mimetype = ''): array + public static function createPhotoForExternalResource(string $url, int $uid = 0, string $mimetype = '', string $blurhash = null, int $width = null, int $height = null): array { if (empty($mimetype)) { $mimetype = Images::guessTypeByExtension($url); @@ -364,6 +389,9 @@ class Photo $photo['backend-ref'] = json_encode(['url' => $url, 'uid' => $uid]); $photo['type'] = $mimetype; $photo['cacheable'] = true; + $photo['blurhash'] = $blurhash; + $photo['width'] = $width; + $photo['height'] = $height; return $photo; } @@ -436,6 +464,7 @@ class Photo 'height' => $image->getHeight(), 'width' => $image->getWidth(), 'datasize' => strlen($image->asString()), + 'blurhash' => $image->getBlurHash(), 'data' => $data, 'scale' => $scale, 'photo-type' => $type, @@ -640,7 +669,11 @@ class Photo $micro = Contact::getDefaultAvatar($contact, Proxy::SIZE_MICRO); } - return [$image_url, $thumb, $micro]; + $photo = DBA::selectFirst( + 'photo', ['blurhash'], ['uid' => $uid, 'contact-id' => $cid, 'scale' => 4, 'photo-type' => self::CONTACT_AVATAR] + ); + + return [$image_url, $thumb, $micro, $photo['blurhash']]; } /** @@ -1318,7 +1351,7 @@ class Photo logger::warning('profile banner upload with scale 3 (960) failed'); } - logger::info('new profile banner upload ended'); + logger::info('new profile banner upload ended', ['uid' => $uid, 'resource_id' => $resource_id, 'filename' => $filename]); $condition = ["`photo-type` = ? AND `resource-id` != ? AND `uid` = ?", self::USER_BANNER, $resource_id, $uid]; self::update(['photo-type' => self::DEFAULT], $condition);