diff --git a/app/Transformer/Api/Mastodon/v1/MediaTransformer.php b/app/Transformer/Api/Mastodon/v1/MediaTransformer.php index ceb96abec..4c04410e5 100644 --- a/app/Transformer/Api/Mastodon/v1/MediaTransformer.php +++ b/app/Transformer/Api/Mastodon/v1/MediaTransformer.php @@ -9,7 +9,7 @@ class MediaTransformer extends Fractal\TransformerAbstract { public function transform(Media $media) { - return [ + $res = [ 'id' => (string) $media->id, 'type' => lcfirst($media->activityVerb()), 'url' => $media->url(), @@ -17,7 +17,25 @@ class MediaTransformer extends Fractal\TransformerAbstract 'preview_url' => $media->thumbnailUrl(), 'text_url' => null, 'meta' => null, - 'description' => $media->caption + 'description' => $media->caption, + 'blurhash' => $media->blurhash ]; + + if($media->width && $media->height) { + $res['meta'] = [ + 'focus' => [ + 'x' => 0, + 'y' => 0 + ], + 'original' => [ + 'width' => $media->width, + 'height' => $media->height, + 'size' => "{$media->width}x{$media->height}", + 'aspect' => $media->width / $media->height + ] + ]; + } + + return $res; } } \ No newline at end of file diff --git a/app/Transformer/Api/MediaTransformer.php b/app/Transformer/Api/MediaTransformer.php index 6b1afd9ca..beb672a0d 100644 --- a/app/Transformer/Api/MediaTransformer.php +++ b/app/Transformer/Api/MediaTransformer.php @@ -9,7 +9,7 @@ class MediaTransformer extends Fractal\TransformerAbstract { public function transform(Media $media) { - return [ + $res = [ 'id' => (string) $media->id, 'type' => $media->activityVerb(), 'url' => $media->url() . '?cb=1&_v=' . time(), @@ -26,5 +26,22 @@ class MediaTransformer extends Fractal\TransformerAbstract 'mime' => $media->mime, 'blurhash' => $media->blurhash ]; + + if($media->width && $media->height) { + $res['meta'] = [ + 'focus' => [ + 'x' => 0, + 'y' => 0 + ], + 'original' => [ + 'width' => $media->width, + 'height' => $media->height, + 'size' => "{$media->width}x{$media->height}", + 'aspect' => $media->width / $media->height + ] + ]; + } + + return $res; } }