-
Notifications
You must be signed in to change notification settings - Fork 1
(Enum.OutOfBoundsError) out of bounds error #2
Copy link
Copy link
Open
Description
I'm trying to decode an image, but it always throws this error:
iex(1)> file = "/home/alex/Pictures/me-avatar.png"
"/home/alex/Pictures/me-avatar.png"
iex(2)> image = Mogrify.open(file) |> Mogrify.verbose() |> Mogrify.format("rgb") |> Mogrify.save()
%Mogrify.Image{
animated: false,
buffer: nil,
dirty: %{},
ext: ".rgb",
format: "rgb",
frame_count: 1,
height: 600,
operations: [],
path: "/tmp/529046-me-avatar.rgb",
width: 600
}
iex(3)> pixels = File.read!(image.path) |> :binary.bin_to_list()
[112, 208, 0, 112, 208, 0, 112, 208, 0, 112, 208, 0, 112, 208, 0, 112, 208, 0,
112, 208, 0, 112, 208, 0, 112, 208, 0, 112, 208, 0, 112, 208, 0, 112, 208, 0,
112, 208, 0, 112, 208, 0, 112, 208, 0, 112, 208, 0, 112, 208, ...]
iex(4)> BlurHash.encode(pixels, 600, 600, 4, 4)
[error] Task #PID<0.1052.0> started from #PID<0.1040.0> terminating
** (Enum.OutOfBoundsError) out of bounds error
(elixir 1.11.2) lib/enum.ex:884: Enum.fetch!/2
(blurhash 1.0.0) lib/blur_hash.ex:107: anonymous fn/10 in BlurHash.get_factors/5
(elixir 1.11.2) lib/enum.ex:3449: Enum.reduce_range_inc/4
(blurhash 1.0.0) lib/blur_hash.ex:92: anonymous fn/8 in BlurHash.get_factors/5
(elixir 1.11.2) lib/task/supervised.ex:90: Task.Supervised.invoke_mfa/2
(elixir 1.11.2) lib/task/supervised.ex:35: Task.Supervised.reply/5
(stdlib 3.14.1) proc_lib.erl:226: :proc_lib.init_p_do_apply/3
Function: #Function<5.74243370/0 in BlurHash.get_factors/5>
Args: []
** (EXIT from #PID<0.1040.0>) shell process exited with reason: an exception was raised:
** (Enum.OutOfBoundsError) out of bounds error
(elixir 1.11.2) lib/enum.ex:884: Enum.fetch!/2
(blurhash 1.0.0) lib/blur_hash.ex:107: anonymous fn/10 in BlurHash.get_factors/5
(elixir 1.11.2) lib/enum.ex:3449: Enum.reduce_range_inc/4
(blurhash 1.0.0) lib/blur_hash.ex:92: anonymous fn/8 in BlurHash.get_factors/5
(elixir 1.11.2) lib/task/supervised.ex:90: Task.Supervised.invoke_mfa/2
(elixir 1.11.2) lib/task/supervised.ex:35: Task.Supervised.reply/5
(stdlib 3.14.1) proc_lib.erl:226: :proc_lib.init_p_do_apply/3I've had better luck hardcoding the value to 30, no matter the real image size:
iex(4)> BlurHash.encode(pixels, 30, 30, 4, 4)
"UKMQ*Jx]t7x]nlt7RkRj~qs=WBR%^+V[ozoM"This at least returns a blurhash, but it doesn't look quite right.
So I tried resizing the image to 30x30 first:
file =
image
|> Mogrify.format("rgb")
|> Mogrify.resize("30x30")
|> Mogrify.save()
pixels =
File.read!(file.path)
|> :binary.bin_to_list()
BlurHash.encode(pixels, 30, 30, 4, 4)But this just gives me the OutOfBoundsError as before. 😕
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels