<?php
/**
- * @copyright Copyright (C) 2020, Friendica
+ * @copyright Copyright (C) 2010-2021, the Friendica project
*
* @license GNU AGPL version 3 or any later version
*
*/
public static function getImageDataForPhoto(array $photo)
{
+ if (!empty($photo['data'])) {
+ return $photo['data'];
+ }
+
$backendClass = DI::storageManager()->getByName($photo['backend-class'] ?? '');
- if ($backendClass === null) {
+ if (empty($backendClass)) {
// legacy data storage in "data" column
$i = self::selectFirst(['data'], ['id' => $photo['id']]);
if ($i === false) {
$storage = DI::storage();
}
- if ($storage === null) {
+ if (empty($storage)) {
$data = $Image->asString();
} else {
$backend_ref = $storage->put($Image->asString(), $backend_ref);
while ($photo = DBA::fetch($photos)) {
$backend_class = DI::storageManager()->getByName($photo['backend-class'] ?? '');
- if ($backend_class !== null) {
+ if (!empty($backend_class)) {
if ($backend_class->delete($photo["backend-ref"] ?? '')) {
// Delete the photos after they had been deleted successfully
DBA::delete("photo", ['id' => $photo['id']]);
foreach($photos as $photo) {
$backend_class = DI::storageManager()->getByName($photo['backend-class'] ?? '');
- if ($backend_class !== null) {
+ if (!empty($backend_class)) {
$fields["backend-ref"] = $backend_class->put($img->asString(), $photo['backend-ref']);
} else {
$fields["data"] = $img->asString();
if ($Image->isValid()) {
$Image->scaleToSquare(300);
+ $filesize = strlen($Image->asString());
+ $maximagesize = DI::config()->get('system', 'maximagesize');
+ if (!empty($maximagesize) && ($filesize > $maximagesize)) {
+ Logger::info('Avatar exceeds image limit', ['uid' => $uid, 'cid' => $cid, 'maximagesize' => $maximagesize, 'size' => $filesize, 'type' => $Image->getType()]);
+ if ($Image->getType() == 'image/gif') {
+ $Image->toStatic();
+ $Image = new Image($Image->asString(), 'image/png');
+
+ $filesize = strlen($Image->asString());
+ Logger::info('Converted gif to a static png', ['uid' => $uid, 'cid' => $cid, 'size' => $filesize, 'type' => $Image->getType()]);
+ }
+ if ($filesize > $maximagesize) {
+ foreach ([160, 80] as $pixels) {
+ if ($filesize > $maximagesize) {
+ Logger::info('Resize', ['uid' => $uid, 'cid' => $cid, 'size' => $filesize, 'max' => $maximagesize, 'pixels' => $pixels, 'type' => $Image->getType()]);
+ $Image->scaleDown($pixels);
+ $filesize = strlen($Image->asString());
+ }
+ }
+ }
+ Logger::info('Avatar is resized', ['uid' => $uid, 'cid' => $cid, 'size' => $filesize, 'type' => $Image->getType()]);
+ }
+
$r = self::store($Image, $uid, $cid, $resource_id, $filename, self::CONTACT_PHOTOS, 4);
if ($r === false) {