From 74b10708ae201f52872bdcf44c4e562052a7156c Mon Sep 17 00:00:00 2001 From: Thorsten Date: Fri, 18 Nov 2022 09:42:53 +0100 Subject: [PATCH] Add meta tag to attachment to show images in mastodon app. --- src/Object/Api/Mastodon/Attachment.php | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/Object/Api/Mastodon/Attachment.php b/src/Object/Api/Mastodon/Attachment.php index dc92ff38cf..8156155cde 100644 --- a/src/Object/Api/Mastodon/Attachment.php +++ b/src/Object/Api/Mastodon/Attachment.php @@ -44,6 +44,8 @@ class Attachment extends BaseDataTransferObject protected $text_url; /** @var string */ protected $description; + /** @var array */ + protected $meta; /** * Creates an attachment @@ -60,6 +62,17 @@ class Attachment extends BaseDataTransferObject $this->remote_url = $remote; $this->text_url = $this->remote_url ?? $this->url; $this->description = $attachment['description']; + if ($type === 'image') { + $this->meta['original']['width'] = (int) $attachment['width']; + $this->meta['original']['height'] = (int) $attachment['height']; + $this->meta['original']['size'] = (int) $attachment['width'] . 'x' . (int) $attachment['height']; + $this->meta['original']['aspect'] = (float) ((int) $attachment['width'] / (int) $attachment['height']); + + $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']; + $this->meta['small']['aspect'] = (float) ((int) $attachment['preview-width'] / (int) $attachment['preview-height']); + } } /**