mirror of
https://github.com/friendica/friendica
synced 2025-04-26 07:10:12 +00:00
Ensure $attachment has a width and a height when it's an image in Mastodon\Attachment
- Address https://github.com/friendica/friendica/issues/11993#issuecomment-1323274513
This commit is contained in:
parent
a5af1408d6
commit
7c6d54c989
2 changed files with 16 additions and 6 deletions
|
@ -22,6 +22,8 @@
|
|||
namespace Friendica\Object\Api\Mastodon;
|
||||
|
||||
use Friendica\BaseDataTransferObject;
|
||||
use Friendica\Core\Logger;
|
||||
use Friendica\Core\System;
|
||||
|
||||
/**
|
||||
* Class Attachment
|
||||
|
@ -50,8 +52,12 @@ class Attachment extends BaseDataTransferObject
|
|||
/**
|
||||
* Creates an attachment
|
||||
*
|
||||
* @param array $attachment
|
||||
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
|
||||
* @param array $attachment Expected keys: id, description
|
||||
* If $type == 'image': width, height[, preview-width, preview-height]
|
||||
* @param string $type One of: audio, video, gifv, image, unknown
|
||||
* @param string $url
|
||||
* @param string $preview
|
||||
* @param string $remote
|
||||
*/
|
||||
public function __construct(array $attachment, string $type, string $url, string $preview, string $remote)
|
||||
{
|
||||
|
@ -70,7 +76,7 @@ class Attachment extends BaseDataTransferObject
|
|||
$this->meta['original']['aspect'] = (float) ((int) $attachment['width'] / (int) $attachment['height']);
|
||||
}
|
||||
|
||||
if ((int) $attachment['preview-width'] > 0 && (int) $attachment['preview-height'] > 0) {
|
||||
if (isset($attachment['preview-width']) && (int) $attachment['preview-width'] > 0 && (int) $attachment['preview-height'] > 0) {
|
||||
$this->meta['small']['width'] = (int) $attachment['preview-width'];
|
||||
$this->meta['small']['height'] = (int) $attachment['preview-height'];
|
||||
$this->meta['small']['size'] = (int) $attachment['preview-width'] . 'x' . (int) $attachment['preview-height'];
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue