Merge pull request #12333 from annando/issue-12327

Issue 12327: Convert avatars to static
pull/12337/head
Hypolite Petovan 2022-12-04 23:30:58 -05:00 committed by GitHub
commit 32a9f39768
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 31 additions and 8 deletions

View File

@ -2057,9 +2057,10 @@ class Contact
* @param integer $cid contact id
* @param string $size One of the Proxy::SIZE_* constants
* @param string $updated Contact update date
* @param bool $static If "true" a parameter is added to convert the avatar to a static one
* @return string avatar link
*/
public static function getAvatarUrlForId(int $cid, string $size = '', string $updated = '', string $guid = ''): string
public static function getAvatarUrlForId(int $cid, string $size = '', string $updated = '', string $guid = '', bool $static = false): string
{
// We have to fetch the "updated" variable when it wasn't provided
// The parameter can be provided to improve performance
@ -2089,7 +2090,15 @@ class Contact
$url .= Proxy::PIXEL_LARGE . '/';
break;
}
return $url . ($guid ?: $cid) . ($updated ? '?ts=' . strtotime($updated) : '');
$query_params = [];
if ($updated) {
$query_params['ts'] = strtotime($updated);
}
if ($static) {
$query_params['static'] = true;
}
return $url . ($guid ?: $cid) . (!empty($query_params) ? '?' . http_build_query($query_params) : '');
}
/**
@ -2114,9 +2123,10 @@ class Contact
* @param integer $cid contact id
* @param string $size One of the Proxy::SIZE_* constants
* @param string $updated Contact update date
* @param bool $static If "true" a parameter is added to convert the header to a static one
* @return string header link
*/
public static function getHeaderUrlForId(int $cid, string $size = '', string $updated = '', string $guid = ''): string
public static function getHeaderUrlForId(int $cid, string $size = '', string $updated = '', string $guid = '', bool $static = false): string
{
// We have to fetch the "updated" variable when it wasn't provided
// The parameter can be provided to improve performance
@ -2147,7 +2157,15 @@ class Contact
break;
}
return $url . ($guid ?: $cid) . ($updated ? '?ts=' . strtotime($updated) : '');
$query_params = [];
if ($updated) {
$query_params['ts'] = strtotime($updated);
}
if ($static) {
$query_params['static'] = true;
}
return $url . ($guid ?: $cid) . (!empty($query_params) ? '?' . http_build_query($query_params) : '');
}
/**

View File

@ -23,7 +23,6 @@ namespace Friendica\Module;
use Friendica\BaseModule;
use Friendica\Core\System;
use Friendica\Database\DBA;
use Friendica\DI;
use Friendica\Model\APContact;
use Friendica\Model\User;

View File

@ -182,6 +182,12 @@ class Photo extends BaseModule
throw new HTTPException\InternalServerErrorException($error);
}
if (!empty($request['static'])) {
$img = new Image($imgdata, $photo['type']);
$img->toStatic();
$imgdata = $img->asString();
}
// if customsize is set and image is not a gif, resize it
if ($photo['type'] !== 'image/gif' && $customsize > 0 && $customsize <= Proxy::PIXEL_THUMB && $square_resize) {
$img = new Image($imgdata, $photo['type']);

View File

@ -109,9 +109,9 @@ class Account extends BaseDataTransferObject
$this->note = BBCode::convertForUriId($account['uri-id'], $account['about'], BBCode::EXTERNAL);
$this->url = $account['url'];
$this->avatar = Contact::getAvatarUrlForId($account['id'] ?? 0 ?: $account['pid'], Proxy::SIZE_SMALL, $account['updated'], $account['guid'] ?? '');
$this->avatar_static = $this->avatar;
$this->avatar_static = Contact::getAvatarUrlForId($account['id'] ?? 0 ?: $account['pid'], Proxy::SIZE_SMALL, $account['updated'], $account['guid'] ?? '', true);
$this->header = Contact::getHeaderUrlForId($account['id'] ?? 0 ?: $account['pid'], '', $account['updated'], $account['guid'] ?? '');
$this->header_static = $this->header;
$this->header_static = Contact::getHeaderUrlForId($account['id'] ?? 0 ?: $account['pid'], '', $account['updated'], $account['guid'] ?? '', true);
$this->followers_count = $account['ap-followers_count'] ?? $account['diaspora-interacted_count'] ?? 0;
$this->following_count = $account['ap-following_count'] ?? $account['diaspora-interacting_count'] ?? 0;
$this->statuses_count = $account['ap-statuses_count'] ?? $account['diaspora-post_count'] ?? 0;

View File

@ -751,7 +751,7 @@ class Image
$row = [];
for ($x = 0; $x < $width; ++$x) {
$index = imagecolorat($this->image, $x, $y);
$colors = imagecolorsforindex($this->image, $index);
$colors = @imagecolorsforindex($this->image, $index);
$row[] = [$colors['red'], $colors['green'], $colors['blue']];
}