diff --git a/Web/Models/Entities/Photo.php b/Web/Models/Entities/Photo.php index ed8dc7ba..8862f8a1 100644 --- a/Web/Models/Entities/Photo.php +++ b/Web/Models/Entities/Photo.php @@ -48,18 +48,22 @@ class Photo extends Media function getDimensions(): array { - $hash = $this->getRecord()->hash; + $x = $this->getRecord()->width; + $y = $this->getRecord()->height; + if(!$x) { # no sizes in database + $hash = $this->getRecord()->hash; + $image = new \Imagick($this->pathFromHash($hash)); - return array_slice(getimagesize($this->pathFromHash($hash)), 0, 2); + $x = $image->getImageWidth(); + $y = $image->getImageHeight(); + $this->stateChanges("width", $x); + $this->stateChanges("height", $y); + $this->save(); + } + + return [$x, $y]; } - function getDimentions(): array - { - trigger_error("getDimentions is deprecated, use Photo::getDimensions instead."); - - return $this->getDimensions(); - } - function getAlbum(): ?Album { return (new Albums)->getAlbumByPhotoId($this); diff --git a/install/sqls/00020-image-sizes.sql b/install/sqls/00020-image-sizes.sql new file mode 100644 index 00000000..e2838f05 --- /dev/null +++ b/install/sqls/00020-image-sizes.sql @@ -0,0 +1,3 @@ +ALTER TABLE `photos` ROW_FORMAT=COMPRESSED; +ALTER TABLE `photos` ADD COLUMN `sizes` VARBINARY(256) NULL DEFAULT NULL AFTER `hash`; +ALTER TABLE `photos` ADD COLUMN `width` SMALLINT UNSIGNED NULL DEFAULT NULL AFTER `sizes`, ADD COLUMN `height` SMALLINT UNSIGNED NULL DEFAULT NULL AFTER `sizes`;