Skip to content

Commit 316a16b

Browse files
Plamenweaverryan
authored andcommitted
handle unresolvable image file++
1 parent ab2825a commit 316a16b

File tree

1 file changed

+20
-28
lines changed

1 file changed

+20
-28
lines changed

src/LazyImage/BlurHash/BlurHash.php

Lines changed: 20 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,6 @@ public function createDataUriThumbnail(string $filename, int $width, int $height
3333
// Resize and encode
3434
$encoded = $this->encode($filename, $encodingWidth, $encodingHeight);
3535

36-
if ($encoded instanceof \Exception) {
37-
// Return 1 x 1 pixel transparent PNG
38-
return 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNkYAAAAAYAAjCB0C8AAAAASUVORK5CYII=';
39-
}
40-
4136
// Create a new blurred thumbnail from encoded BlurHash
4237
$pixels = \kornrunner\Blurhash\Blurhash::decode($encoded, $width, $height);
4338

@@ -57,31 +52,28 @@ public function encode(string $filename, int $encodingWidth = 75, int $encodingH
5752
throw new \LogicException("Missing package, to use the \"blur_hash\" Twig function, run:\n\ncomposer require intervention/image");
5853
}
5954

60-
try {
61-
// Resize image to increase encoding performance
62-
$image = $this->imageManager->make(file_get_contents($filename));
63-
$image->resize($encodingWidth, $encodingHeight, static function ($constraint) {
64-
$constraint->aspectRatio();
65-
$constraint->upsize();
66-
});
55+
// Resize image to increase encoding performance
56+
$image = $this->imageManager->make(file_get_contents($filename));
57+
$image->resize($encodingWidth, $encodingHeight, static function ($constraint) {
58+
$constraint->aspectRatio();
59+
$constraint->upsize();
60+
});
6761

68-
// Encode using BlurHash
69-
$width = $image->getWidth();
70-
$height = $image->getHeight();
62+
// Encode using BlurHash
63+
$width = $image->getWidth();
64+
$height = $image->getHeight();
7165

72-
$pixels = [];
73-
for ($y = 0; $y < $height; ++$y) {
74-
$row = [];
75-
for ($x = 0; $x < $width; ++$x) {
76-
$color = $image->pickColor($x, $y);
77-
$row[] = [$color[0], $color[1], $color[2]];
78-
}
79-
80-
$pixels[] = $row;
66+
$pixels = [];
67+
for ($y = 0; $y < $height; ++$y) {
68+
$row = [];
69+
for ($x = 0; $x < $width; ++$x) {
70+
$color = $image->pickColor($x, $y);
71+
$row[] = [$color[0], $color[1], $color[2]];
8172
}
82-
return \kornrunner\Blurhash\Blurhash::encode($pixels, 4, 3);
83-
} catch (\Exception $e) {
84-
return $e;
85-
}
73+
74+
$pixels[] = $row;
75+
}
76+
77+
return \kornrunner\Blurhash\Blurhash::encode($pixels, 4, 3);
8678
}
8779
}

0 commit comments

Comments
 (0)