Use the blurhash when the remote picture doesn't load

This commit is contained in:
Michael 2022-12-04 14:58:53 +00:00
parent a5be5b27e3
commit cfe5101b9b
3 changed files with 34 additions and 12 deletions

View file

@ -780,13 +780,21 @@ class Image
return;
}
$pixels = Blurhash::decode($blurhash, $width, $height);
$this->image = imagecreatetruecolor($width, $height);
for ($y = 0; $y < $height; ++$y) {
for ($x = 0; $x < $width; ++$x) {
$scaled = Images::getScalingDimensions($width, $height, 90);
$pixels = Blurhash::decode($blurhash, $scaled['width'], $scaled['height']);
$this->image = imagecreatetruecolor($scaled['width'], $scaled['height']);
for ($y = 0; $y < $scaled['height']; ++$y) {
for ($x = 0; $x < $scaled['width']; ++$x) {
[$r, $g, $b] = $pixels[$y][$x];
imagesetpixel($this->image, $x, $y, imagecolorallocate($this->image, $r, $g, $b));
}
}
$this->width = imagesx($this->image);
$this->height = imagesy($this->image);
$this->valid = true;
$this->scaleUp(min($width, $height));
}
}