mirror of
https://github.com/openvk/openvk
synced 2024-12-22 16:42:32 +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,18 +48,22 @@ class Photo extends Media
|
||||||
|
|
||||||
function getDimensions(): array
|
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
|
function getAlbum(): ?Album
|
||||||
{
|
{
|
||||||
return (new Albums)->getAlbumByPhotoId($this);
|
return (new Albums)->getAlbumByPhotoId($this);
|
||||||
|
|
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