Cache image resolution in database

This commit is contained in:
Celestora 2022-04-05 11:38:19 +03:00
parent 0c2d3844bc
commit f707c72f07
2 changed files with 16 additions and 9 deletions

View file

@ -48,16 +48,20 @@ class Photo extends Media
function getDimensions(): array
{
$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();
}
function getDimentions(): array
{
trigger_error("getDimentions is deprecated, use Photo::getDimensions instead.");
return $this->getDimensions();
return [$x, $y];
}
function getAlbum(): ?Album

View file

@ -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`;