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/3
I'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. ๐
Recommend Projects
-
-
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
An Open Source Machine Learning Framework for Everyone
-
The Web framework for perfectionists with deadlines.
-
A PHP framework for web artisans
-
Bring data to life with SVG, Canvas and HTML. ๐๐๐
-
Recommend Topics
-
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
Some thing interesting about web. New door for the world.
-
A server is a program made to process requests and deliver data to clients.
-
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Some thing interesting about visualization, use data art
-
Some thing interesting about game, make everyone happy.
-
Recommend Org
-
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Open source projects and samples from Microsoft.
-
Google โค๏ธ Open Source for everyone.
-
Alibaba Open Source for everyone
-
Data-Driven Documents codes.
-
China tencent open source team.
-