IwoHerka

IwoHerka

How to draw transparency using :egd?

I cannot get drawing transparency to work. How can I make :egd to set alpha properly?

image = :egd.create(100, 100)
# Use any color with alpha = 0
:egd.filledRectangle(image, {0, 0}, {99, 99}, :egd.color({25, 123, 0, 0}))
:egd.render(image, :png)
# or :egd.render(image, :png, [render_engine: :alpha])
:edg.save(image, "image.png")

The above produces solid-color image, instead a transparent one. Am I doing something wrong?

Thanks!

First Post!

kip

kip

ex_cldr Core Team

Wow, the :egd documentation is not very expansive!

The only thing I can think of is to assert on the function. It’s a strange module in that it mutates too! Perhaps try this and see if you get any exceptions?

image = :egd.create(100, 100)
# Use any color with alpha = 0
:ok = :egd.filledRectangle(image, {0, 0}, {99, 99}, :egd.color({25, 123, 0, 0}))
:edg.save(image, "image.png")

Edit:

Hmmm since you get a solid color image I guess the filledRectangle/4 call is working as expected.

Last Post!

IwoHerka

IwoHerka

I get an exception, but because not calling render first makes image invalid type for save. render returns Binary::binary() which save excepts. Before call to render, image is of type Image::egd_image().

Where Next?

Popular in Questions Top

Qqwy
Original source of discussion: This topic on the Pragmatic Programmers’ Functional Web Development with Elixir, OTP, and Phoenix forum. ...
New
skosch
To my knowledge, put_in, Map.update etc. all have the one limitation of not automatically creating intermediate keys when needed (for exa...
New
PeterCarter
There are pre-rolled solutions for other frameworks that do work. However, Phoenix does not seem to have these. Have people had good expe...
New
stefanchrobot
What’s the safe way to decode a JSON string into a struct? I want to avoid calling String.to_atom. Jason.decode can give me a map with st...
New
Lily
In templates/appointment/index.html.eex: <%= for appointment <- @appointments do %> <tr> <td><%= appoi...
New
Darmani72
If I have a post route which an argument: post /my_post_route/:my_param1, MyController.my_post_handler How would get the post params ...
New
gshaw
What is the idiomatic way of matching for not nil in Elixir? E.g., First way: defp halt_if_not_signed_in(conn, signed_in_account) when...
New

Other popular topics Top

chrismccord
Phoenix 1.4.0 released Phoenix 1.4 is out! This release ships with exciting new features, most notably with HTTP2 support, improved deve...
688 31586 112
New
sen
Hi All, I set a environment variables in dev.exs , like below code. when i start server, how can i set the ${enable} value? thanks. d...
New
sorentwo
Hello! tl;dr Announcing Oban, an Ecto based job processing library with a focus on reliability and historical observability. After spen...
985 44778 311
New
WestKeys
Currently suffering from paralysis by [HTTP client] analysis. This is rather unusual in Elixirland as there tends to be consensus on the ...
New
dblack
I’ve got an issue with an app and I’ve no idea of how to troubleshoot it. I’m hoping someone here might have seen something similar. I p...
New
romenigld
I am trying to run a deploy with docker and I successfully runned with this command: docker build -t romenigld/blog-prod . but when I t...
New

We're in Beta

About us Mission Statement