Merge pull request #12341 from annando/fix-small-preview

The BlurHash function must not change the original image
This commit is contained in:
Philipp 2022-12-05 21:45:37 +01:00 committed by GitHub
commit 8543174bf1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -733,25 +733,27 @@ class Image
*/ */
public function getBlurHash(): string public function getBlurHash(): string
{ {
$width = $this->getWidth(); $image = New Image($this->asString());
$height = $this->getHeight();
$width = $image->getWidth();
$height = $image->getHeight();
if (max($width, $height) > 90) { if (max($width, $height) > 90) {
$this->scaleDown(90); $image->scaleDown(90);
$width = $this->getWidth(); $width = $image->getWidth();
$height = $this->getHeight(); $height = $image->getHeight();
} }
$pixels = []; $pixels = [];
for ($y = 0; $y < $height; ++$y) { for ($y = 0; $y < $height; ++$y) {
$row = []; $row = [];
for ($x = 0; $x < $width; ++$x) { for ($x = 0; $x < $width; ++$x) {
if ($this->isImagick()) { if ($image->isImagick()) {
$colors = $this->image->getImagePixelColor($x, $y)->getColor(); $colors = $image->image->getImagePixelColor($x, $y)->getColor();
$row[] = [$colors['r'], $colors['g'], $colors['b']]; $row[] = [$colors['r'], $colors['g'], $colors['b']];
} else { } else {
$index = imagecolorat($this->image, $x, $y); $index = imagecolorat($image->image, $x, $y);
$colors = @imagecolorsforindex($this->image, $index); $colors = @imagecolorsforindex($image->image, $index);
$row[] = [$colors['red'], $colors['green'], $colors['blue']]; $row[] = [$colors['red'], $colors['green'], $colors['blue']];
} }
} }