diff options
| author | Mark Felder <feld@feld.me> | 2023-11-23 16:15:53 -0500 | 
|---|---|---|
| committer | Mark Felder <feld@feld.me> | 2023-11-23 16:15:53 -0500 | 
| commit | 299c548b124377e51f6c089bc0df31b2989be3ef (patch) | |
| tree | 5da2ba11ca52df9860bdcff838c431ee824639fd /lib | |
| parent | 906b121a1053557016734be0bf224c5ad317ee08 (diff) | |
| download | pleroma-299c548b124377e51f6c089bc0df31b2989be3ef.tar.gz pleroma-299c548b124377e51f6c089bc0df31b2989be3ef.zip | |
Prevent a blurhash failure from breaking all metadata collection
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/pleroma/upload/filter/analyze_metadata.ex | 34 | 
1 files changed, 18 insertions, 16 deletions
| diff --git a/lib/pleroma/upload/filter/analyze_metadata.ex b/lib/pleroma/upload/filter/analyze_metadata.ex index 99d1ec5bc..92b80b1b1 100644 --- a/lib/pleroma/upload/filter/analyze_metadata.ex +++ b/lib/pleroma/upload/filter/analyze_metadata.ex @@ -83,21 +83,23 @@ defmodule Pleroma.Upload.Filter.AnalyzeMetadata do    end    defp vips_blurhash(image = %Vix.Vips.Image{}) do -    {:ok, resized_image} = Operation.thumbnail_image(image, 100) -    {height, width} = {Image.height(resized_image), Image.width(resized_image)} -    max = max(height, width) -    {x, y} = {max(round(width * 5 / max), 1), max(round(height * 5 / max), 1)} - -    {: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 - -    rgba = List.flatten(rgba) - -    Blurhash.encode(x, y, width, height, rgba) +    with {:ok, resized_image} <- Operation.thumbnail_image(image, 100), +         {height, width} <- {Image.height(resized_image), Image.width(resized_image)}, +         max <- max(height, width), +         {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 + +      rgba = List.flatten(rgba) + +      Blurhash.encode(x, y, width, height, rgba) +    else +      _ -> nil +    end    end  end | 
