pixelfed/app/Transformer/Api/Mastodon/v1/MediaTransformer.php

41 lines
1.2 KiB
PHP
Raw Permalink Normal View History

2019-09-26 07:30:15 +00:00
<?php
namespace App\Transformer\Api\Mastodon\v1;
use App\Media;
use League\Fractal;
class MediaTransformer extends Fractal\TransformerAbstract
{
public function transform(Media $media)
{
$res = [
2019-09-26 07:30:15 +00:00
'id' => (string) $media->id,
'type' => lcfirst($media->activityVerb()),
'url' => $media->url(),
'preview_url' => $media->thumbnailUrl(),
2022-01-03 06:26:18 +00:00
'remote_url' => $media->remote_url,
'text_url' => $media->url(),
'description' => $media->caption,
'blurhash' => $media->blurhash ?? 'U4Rfzst8?bt7ogayj[j[~pfQ9Goe%Mj[WBay'
2019-09-26 07:30:15 +00:00
];
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;
2019-09-26 07:30:15 +00:00
}
2022-01-03 06:26:18 +00:00
}