use Friendica\BaseEntity;
use Friendica\Network\Entity\MimeType;
+use Friendica\Util\Images;
use Friendica\Util\Proxy;
use Psr\Http\Message\UriInterface;
$this->id;
}
+
+ /**
+ * Return a new PostMedia entity with a different preview URI and an optional proxy size name.
+ * The new entity preview's width and height are rescaled according to the provided size.
+ *
+ * @param \GuzzleHttp\Psr7\Uri $preview
+ * @param string $size
+ * @return $this
+ */
+ public function withPreview(\GuzzleHttp\Psr7\Uri $preview, string $size = ''): self
+ {
+ if ($this->width || $this->height) {
+ $newWidth = $this->width;
+ $newHeight = $this->height;
+ } else {
+ $newWidth = $this->previewWidth;
+ $newHeight = $this->previewHeight;
+ }
+
+ if ($newWidth && $newHeight && $size) {
+ $dimensionts = Images::getScalingDimensions($newWidth, $newHeight, Proxy::getPixelsFromSize($size));
+ $newWidth = $dimensionts['width'];
+ $newHeight = $dimensionts['height'];
+ }
+
+ return new static(
+ $this->uriId,
+ $this->url,
+ $this->type,
+ $this->mimetype,
+ $this->activityUriId,
+ $this->width,
+ $this->height,
+ $this->size,
+ $preview,
+ $newWidth,
+ $newHeight,
+ $this->description,
+ $this->name,
+ $this->authorUrl,
+ $this->authorName,
+ $this->authorImage,
+ $this->publisherUrl,
+ $this->publisherName,
+ $this->publisherImage,
+ $this->blurhash,
+ $this->id,
+ );
+ }
+
+ public function withUrl(\GuzzleHttp\Psr7\Uri $url): self
+ {
+ return new static(
+ $this->uriId,
+ $url,
+ $this->type,
+ $this->mimetype,
+ $this->activityUriId,
+ $this->width,
+ $this->height,
+ $this->size,
+ $this->preview,
+ $this->previewWidth,
+ $this->previewHeight,
+ $this->description,
+ $this->name,
+ $this->authorUrl,
+ $this->authorName,
+ $this->authorImage,
+ $this->publisherUrl,
+ $this->publisherName,
+ $this->publisherImage,
+ $this->blurhash,
+ $this->id,
+ );
+ }
}
}
/**
- * @param array $images
+ * @param PostMedias $images
* @return string
* @throws \Friendica\Network\HTTPException\ServiceUnavailableException
*/
- private static function makeImageGrid(array $images): string
+ private static function makeImageGrid(PostMedias $images): string
{
// Image for first column (fc) and second column (sc)
$images_fc = [];
DI::profiler()->startRecording('rendering');
$leading = '';
$trailing = '';
- $images = [];
+ $images = new PostMedias();
// @todo In the future we should make a single for the template engine with all media in it. This allows more flexibilty.
foreach ($PostMedias as $PostMedia) {
}
if ($PostMedia->mimetype->type == 'image') {
- $preview_url = DI::baseUrl() . $PostMedia->getPreviewPath($PostMedia->width > $PostMedia->height ? Proxy::SIZE_MEDIUM : Proxy::SIZE_LARGE);
+ $preview_size = $PostMedia->width > $PostMedia->height ? Proxy::SIZE_MEDIUM : Proxy::SIZE_LARGE;
+ $preview_url = DI::baseUrl() . $PostMedia->getPreviewPath($preview_size);
} elseif ($PostMedia->preview) {
- $preview_url = DI::baseUrl() . $PostMedia->getPreviewPath(Proxy::SIZE_LARGE);
+ $preview_size = Proxy::SIZE_LARGE;
+ $preview_url = DI::baseUrl() . $PostMedia->getPreviewPath($preview_size);
} else {
+ $preview_size = 0;
$preview_url = '';
}
continue;
}
- $images[] = [
- 'src' => $src_url,
- 'preview' => $preview_url,
- 'attachment' => $PostMedia,
- ];
+ $images[] = $PostMedia->withUrl(new Uri($src_url))->withPreview(new Uri($preview_url), $preview_size);
}
}
-{{if $image.preview}}
-<a data-fancybox="{{$image.attachment->uriId}}" href="{{$image.attachment->url}}"><img src="{{$image.preview}}" alt="{{$image.attachment->description}}" title="{{$image.attachment->description}}" loading="lazy"></a>
+{{if $image->preview}}
+<a data-fancybox="{{$image->uriId}}" href="{{$image->url}}"><img src="{{$image->preview}}" alt="{{$image->description}}" title="{{$image->description}}" loading="lazy"></a>
{{else}}
-<img src="{{$image.src}}" alt="{{$image.attachment->description}}" title="{{$image.attachment->description}}" loading="lazy">
+<img src="{{$image->url}}" alt="{{$image->description}}" title="{{$image->description}}" loading="lazy">
{{/if}}