Prevent a blurhash failure from breaking all metadata collection
This commit is contained in:
parent
906b121a10
commit
299c548b12
|
@ -83,21 +83,23 @@ defp media_dimensions(file) do
|
||||||
end
|
end
|
||||||
|
|
||||||
defp vips_blurhash(image = %Vix.Vips.Image{}) do
|
defp vips_blurhash(image = %Vix.Vips.Image{}) do
|
||||||
{:ok, resized_image} = Operation.thumbnail_image(image, 100)
|
with {:ok, resized_image} <- Operation.thumbnail_image(image, 100),
|
||||||
{height, width} = {Image.height(resized_image), Image.width(resized_image)}
|
{height, width} <- {Image.height(resized_image), Image.width(resized_image)},
|
||||||
max = max(height, width)
|
max <- max(height, width),
|
||||||
{x, y} = {max(round(width * 5 / max), 1), max(round(height * 5 / max), 1)}
|
{x, y} <- {max(round(width * 5 / max), 1), max(round(height * 5 / max), 1)} do
|
||||||
|
{:ok, rgba} =
|
||||||
|
if Image.has_alpha?(resized_image) do
|
||||||
|
Image.to_list(resized_image)
|
||||||
|
else
|
||||||
|
Operation.bandjoin_const!(resized_image, [255])
|
||||||
|
|> Image.to_list()
|
||||||
|
end
|
||||||
|
|
||||||
{:ok, rgba} =
|
rgba = List.flatten(rgba)
|
||||||
if Image.has_alpha?(resized_image) do
|
|
||||||
Image.to_list(resized_image)
|
|
||||||
else
|
|
||||||
Operation.bandjoin_const!(resized_image, [255])
|
|
||||||
|> Image.to_list()
|
|
||||||
end
|
|
||||||
|
|
||||||
rgba = List.flatten(rgba)
|
Blurhash.encode(x, y, width, height, rgba)
|
||||||
|
else
|
||||||
Blurhash.encode(x, y, width, height, rgba)
|
_ -> nil
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue