mirror of
https://github.com/openvk/openvk
synced 2024-12-23 00:51:03 +03:00
Cache image resolution in database
This commit is contained in:
parent
0c2d3844bc
commit
f707c72f07
2 changed files with 16 additions and 9 deletions
|
@ -48,16 +48,20 @@ class Photo extends Media
|
||||||
|
|
||||||
function getDimensions(): array
|
function getDimensions(): array
|
||||||
{
|
{
|
||||||
|
$x = $this->getRecord()->width;
|
||||||
|
$y = $this->getRecord()->height;
|
||||||
|
if(!$x) { # no sizes in database
|
||||||
$hash = $this->getRecord()->hash;
|
$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
|
return [$x, $y];
|
||||||
{
|
|
||||||
trigger_error("getDimentions is deprecated, use Photo::getDimensions instead.");
|
|
||||||
|
|
||||||
return $this->getDimensions();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function getAlbum(): ?Album
|
function getAlbum(): ?Album
|
||||||
|
|
3
install/sqls/00020-image-sizes.sql
Normal file
3
install/sqls/00020-image-sizes.sql
Normal 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`;
|
Loading…
Reference in a new issue