mirror of
https://git.pleroma.social/pleroma/pleroma.git
synced 2025-06-04 23:48:50 +00:00
Merge branch '3355-vips-blurhash' into 'develop'
AnalyzeMetadata: Don't crash on grayscale image blurhash Closes #3355 See merge request pleroma/pleroma!4319
This commit is contained in:
commit
a1f4da7ae2
4 changed files with 22 additions and 3 deletions
1
changelog.d/vips-blurhash.fix
Normal file
1
changelog.d/vips-blurhash.fix
Normal file
|
@ -0,0 +1 @@
|
||||||
|
Fix blurhash generation crashes
|
|
@ -90,9 +90,13 @@ defmodule Pleroma.Upload.Filter.AnalyzeMetadata do
|
||||||
{:ok, rgb} =
|
{:ok, rgb} =
|
||||||
if Image.has_alpha?(resized_image) do
|
if Image.has_alpha?(resized_image) do
|
||||||
# remove alpha channel
|
# remove alpha channel
|
||||||
resized_image
|
case Operation.extract_band(resized_image, 0, n: 3) do
|
||||||
|> Operation.extract_band!(0, n: 3)
|
{:ok, data} ->
|
||||||
|> Image.write_to_binary()
|
Image.write_to_binary(data)
|
||||||
|
|
||||||
|
_ ->
|
||||||
|
Image.write_to_binary(resized_image)
|
||||||
|
end
|
||||||
else
|
else
|
||||||
Image.write_to_binary(resized_image)
|
Image.write_to_binary(resized_image)
|
||||||
end
|
end
|
||||||
|
|
BIN
test/fixtures/break_analyze.png
vendored
Normal file
BIN
test/fixtures/break_analyze.png
vendored
Normal file
Binary file not shown.
After Width: | Height: | Size: 360 KiB |
|
@ -34,6 +34,20 @@ defmodule Pleroma.Upload.Filter.AnalyzeMetadataTest do
|
||||||
assert meta.blurhash == "eXJi-E:SwCEm5rCmn$+YWYn+15K#5A$xxCi{SiV]s*W:Efa#s.jE-T"
|
assert meta.blurhash == "eXJi-E:SwCEm5rCmn$+YWYn+15K#5A$xxCi{SiV]s*W:Efa#s.jE-T"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "it gets dimensions for grayscale images" do
|
||||||
|
upload = %Pleroma.Upload{
|
||||||
|
name: "break_analyze.png",
|
||||||
|
content_type: "image/png",
|
||||||
|
path: Path.absname("test/fixtures/break_analyze.png"),
|
||||||
|
tempfile: Path.absname("test/fixtures/break_analyze.png")
|
||||||
|
}
|
||||||
|
|
||||||
|
{:ok, :filtered, meta} = AnalyzeMetadata.filter(upload)
|
||||||
|
|
||||||
|
assert %{width: 1410, height: 2048} = meta
|
||||||
|
assert is_nil(meta.blurhash)
|
||||||
|
end
|
||||||
|
|
||||||
test "adds the dimensions for videos" do
|
test "adds the dimensions for videos" do
|
||||||
upload = %Pleroma.Upload{
|
upload = %Pleroma.Upload{
|
||||||
name: "coolvideo.mp4",
|
name: "coolvideo.mp4",
|
||||||
|
|
Loading…
Reference in a new issue