uriId = $uriId; $this->url = $url; $this->type = $type; $this->mimetype = $mimetype; $this->activityUriId = $activityUriId; $this->width = $width; $this->height = $height; $this->size = $size; $this->preview = $preview; $this->previewWidth = $previewWidth; $this->previewHeight = $previewHeight; $this->description = $description; $this->name = $name; $this->authorUrl = $authorUrl; $this->authorName = $authorName; $this->authorImage = $authorImage; $this->publisherUrl = $publisherUrl; $this->publisherName = $publisherName; $this->publisherImage = $publisherImage; $this->blurhash = $blurhash; $this->id = $id; } /** * Get media link for given media id * * @param string $size One of the Proxy::SIZE_* constants * @return string media link */ public function getPhotoPath(string $size = ''): string { return '/photo/media/' . (Proxy::getPixelsFromSize($size) ? Proxy::getPixelsFromSize($size) . '/' : '') . $this->id; } /** * Get preview path for given media id relative to the base URL * * @param string $size One of the Proxy::SIZE_* constants * @param bool $vlurred If "true", the preview will be blurred * @return string preview link */ public function getPreviewPath(string $size = '', bool $blurred = false): string { $path = '/photo/preview/' . (Proxy::getPixelsFromSize($size) ? Proxy::getPixelsFromSize($size) . '/' : '') . $this->id; if ($blurred) { $path .= '?' . http_build_query(['blur' => true]); } return $path; } /** * Computes the allocated height value used in the content/image/single_with_height_allocation.tpl template * * Either base or preview dimensions need to be set at runtime. * * @return string */ public function getAllocatedHeight(): string { if (!$this->hasDimensions()) { throw new \RangeException('Either width and height or previewWidth and previewHeight must be defined to use this method.'); } if ($this->width && $this->height) { $width = $this->width; $height = $this->height; } else { $width = $this->previewWidth; $height = $this->previewHeight; } return (100 * $height / $width) . '%'; } /** * 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 self( $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 self( $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, ); } /** * Checks the media has at least one full set of dimensions, needed for the height allocation feature * * @return bool */ public function hasDimensions(): bool { return $this->width && $this->height || $this->previewWidth && $this->previewHeight; } }