mirror of
https://github.com/standardebooks/web.git
synced 2025-07-20 22:33:57 -04:00
Add ?ts=<updated-timestamp>
to ImageUrl and ThumbUrl
Also add new ImageFsPath and ThumbFsPath properties for filesystem operations since they can't build on the Url properties.
This commit is contained in:
parent
7b03175cc7
commit
8b62a9130c
1 changed files with 29 additions and 8 deletions
|
@ -20,6 +20,9 @@ use function Safe\preg_replace;
|
||||||
* @property string $ImageUrl
|
* @property string $ImageUrl
|
||||||
* @property string $ThumbUrl
|
* @property string $ThumbUrl
|
||||||
* @property string $Thumb2xUrl
|
* @property string $Thumb2xUrl
|
||||||
|
* @property string $ImageFsPath
|
||||||
|
* @property string $ThumbFsPath
|
||||||
|
* @property string $Thumb2xFsPath
|
||||||
* @property string $Dimensions
|
* @property string $Dimensions
|
||||||
* @property ArtworkStatus|string|null $Status
|
* @property ArtworkStatus|string|null $Status
|
||||||
* @property Ebook $Ebook
|
* @property Ebook $Ebook
|
||||||
|
@ -55,6 +58,9 @@ class Artwork extends PropertiesBase{
|
||||||
protected ?string $_ImageUrl = null;
|
protected ?string $_ImageUrl = null;
|
||||||
protected ?string $_ThumbUrl = null;
|
protected ?string $_ThumbUrl = null;
|
||||||
protected ?string $_Thumb2xUrl = null;
|
protected ?string $_Thumb2xUrl = null;
|
||||||
|
protected ?string $_ImageFsPath = null;
|
||||||
|
protected ?string $_ThumbFsPath = null;
|
||||||
|
protected ?string $_Thumb2xFsPath = null;
|
||||||
protected ?string $_Dimensions = null;
|
protected ?string $_Dimensions = null;
|
||||||
protected ?Ebook $_Ebook = null;
|
protected ?Ebook $_Ebook = null;
|
||||||
protected ?Museum $_Museum = null;
|
protected ?Museum $_Museum = null;
|
||||||
|
@ -209,7 +215,7 @@ class Artwork extends PropertiesBase{
|
||||||
throw new Exceptions\InvalidArtworkException();
|
throw new Exceptions\InvalidArtworkException();
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->_ImageUrl = COVER_ART_UPLOAD_PATH . $this->ArtworkId . $this->MimeType->GetFileExtension();
|
$this->_ImageUrl = COVER_ART_UPLOAD_PATH . $this->ArtworkId . $this->MimeType->GetFileExtension() . '?ts=' . $this->Updated?->getTimestamp();
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->_ImageUrl;
|
return $this->_ImageUrl;
|
||||||
|
@ -224,34 +230,49 @@ class Artwork extends PropertiesBase{
|
||||||
throw new Exceptions\ArtworkNotFoundException();
|
throw new Exceptions\ArtworkNotFoundException();
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->_ThumbUrl = COVER_ART_UPLOAD_PATH . $this->ArtworkId . '-thumb.jpg';
|
$this->_ThumbUrl = COVER_ART_UPLOAD_PATH . $this->ArtworkId . '-thumb.jpg' . '?ts=' . $this->Updated?->getTimestamp();
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->_ThumbUrl;
|
return $this->_ThumbUrl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @throws \Exceptions\ArtworkNotFoundException
|
||||||
|
*/
|
||||||
protected function GetThumb2xUrl(): string{
|
protected function GetThumb2xUrl(): string{
|
||||||
if($this->_Thumb2xUrl === null){
|
if($this->_Thumb2xUrl === null){
|
||||||
if($this->ArtworkId === null){
|
if($this->ArtworkId === null){
|
||||||
throw new Exceptions\ArtworkNotFoundException();
|
throw new Exceptions\ArtworkNotFoundException();
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->_Thumb2xUrl = COVER_ART_UPLOAD_PATH . $this->ArtworkId . '-thumb@2x.jpg';
|
$this->_Thumb2xUrl = COVER_ART_UPLOAD_PATH . $this->ArtworkId . '-thumb@2x.jpg' . '?ts=' . $this->Updated?->getTimestamp();
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->_Thumb2xUrl;
|
return $this->_Thumb2xUrl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected function GetImageFsPath(): string{
|
||||||
|
return WEB_ROOT . rtrim($this->ImageUrl, '?ts=0123456789');
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function GetThumbFsPath(): string{
|
||||||
|
return WEB_ROOT . rtrim($this->ThumbUrl, '?ts=0123456789');
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function GetThumb2xFsPath(): string{
|
||||||
|
return WEB_ROOT . rtrim($this->Thumb2xUrl, '?ts=0123456789');
|
||||||
|
}
|
||||||
|
|
||||||
protected function GetDimensions(): string{
|
protected function GetDimensions(): string{
|
||||||
$this->_Dimensions = '';
|
$this->_Dimensions = '';
|
||||||
try{
|
try{
|
||||||
list($imageWidth, $imageHeight) = getimagesize(WEB_ROOT . $this->ImageUrl);
|
list($imageWidth, $imageHeight) = getimagesize($this->ImageFsPath);
|
||||||
if($imageWidth && $imageHeight){
|
if($imageWidth && $imageHeight){
|
||||||
$this->_Dimensions = $imageWidth . ' × ' . $imageHeight;
|
$this->_Dimensions = $imageWidth . ' × ' . $imageHeight;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch(Exception){
|
catch(Exception){
|
||||||
// Image doesn't exist, return blank strin
|
// Image doesn't exist, return blank string
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->_Dimensions;
|
return $this->_Dimensions;
|
||||||
|
@ -581,13 +602,13 @@ class Artwork extends PropertiesBase{
|
||||||
|
|
||||||
private function WriteImageAndThumbnails(string $imageUploadPath): void{
|
private function WriteImageAndThumbnails(string $imageUploadPath): void{
|
||||||
exec('exiftool -quiet -overwrite_original -all= ' . escapeshellarg($imageUploadPath));
|
exec('exiftool -quiet -overwrite_original -all= ' . escapeshellarg($imageUploadPath));
|
||||||
copy($imageUploadPath, WEB_ROOT . $this->ImageUrl);
|
copy($imageUploadPath, $this->ImageFsPath);
|
||||||
|
|
||||||
// Generate the thumbnails
|
// Generate the thumbnails
|
||||||
try{
|
try{
|
||||||
$image = new Image($imageUploadPath);
|
$image = new Image($imageUploadPath);
|
||||||
$image->Resize(WEB_ROOT . $this->ThumbUrl, ARTWORK_THUMBNAIL_WIDTH, ARTWORK_THUMBNAIL_HEIGHT);
|
$image->Resize($this->ThumbFsPath, ARTWORK_THUMBNAIL_WIDTH, ARTWORK_THUMBNAIL_HEIGHT);
|
||||||
$image->Resize(WEB_ROOT . $this->Thumb2xUrl, ARTWORK_THUMBNAIL_WIDTH * 2, ARTWORK_THUMBNAIL_HEIGHT * 2);
|
$image->Resize($this->Thumb2xFsPath, ARTWORK_THUMBNAIL_WIDTH * 2, ARTWORK_THUMBNAIL_HEIGHT * 2);
|
||||||
}
|
}
|
||||||
catch(\Safe\Exceptions\FilesystemException | \Safe\Exceptions\ImageException){
|
catch(\Safe\Exceptions\FilesystemException | \Safe\Exceptions\ImageException){
|
||||||
throw new Exceptions\InvalidImageUploadException('Failed to generate thumbnail.');
|
throw new Exceptions\InvalidImageUploadException('Failed to generate thumbnail.');
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue