1
0
Fork 0

Update MediaTransformers, include meta attribute with focus and dimensions

This commit is contained in:
Daniel Supernault 2021-01-19 19:39:04 -07:00
parent 40bd64aae7
commit f8cbe1e42c
No known key found for this signature in database
GPG Key ID: 0DEF1C662C9033F7
2 changed files with 38 additions and 3 deletions

View File

@ -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;
}
}

View File

@ -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;
}
}