LionelMarco

LionelMarco

How to create a transparent background png with Erlang Graphical Drawer?

I am trying to to use EGD to draw a png with information that come from harvest machine logs.

I use to create a png image with a given width an heigth and then
draw color filled circles of specific radius that come from a list
of points, then Leaflet consume the image.

The problem is that the image need to have a transparent background.

def  create_image(w,h,stamps) do

    im = :egd.create(w,h)
    transparent = :egd.color({255,255,255,255})
    :egd.rectangle(im, {1,1}, {w,h}, transparent)
    green = :egd.color({0,255,0,255})
    rad=2

    for %{"x"=>x,"y"=>y,"value"=>value} <- stamps do
      
      :egd.filledEllipse(im, {x-rad,y-rad},{x+rad,y+rad},green)

    end

    :egd.render( im, :png, [{ :render_engine, :alpha}] )
    
end 

I have made many tries:

  1. Just draw the dots without any specification about the background.
    And without the :egd.rectangle(im, {1,1}, {w,h}, transparent)
    and get a white background.

  2. Drawing a rectangle with a white color:

  transparent = :egd.color({255,255,255,255})
   :egd.rectangle(im, {1,1}, {w,h}, transparent)
  1. The same color with another alpha
  transparent = :egd.color({255,255,255,0})
   :egd.rectangle(im, {1,1}, {w,h}, transparent)

Also there isn’t any change if the render function is called

 :egd.render( im, :png, [ render_engine: :alpha] )
 instead of 
 :egd.render( im, :png, [{ :render_engine, :alpha}] )

In both case the alpha of the colors is applied correctly.

Anybody know what supposed to do, the documentation is pretty short,
or any can recommend a only erlang or elixir librarie (no binding to ImageMagic), for this task

Greetings

Where Next?

Popular in Questions Top

jononomo
I am trying to figure out how Mix knows whether the environment is test, dev, or prod -- where is this set? Thanks.
New
Tee
can someone please explain to me how Enum.reduce works with maps
New
JorisKok
I have a server on AWS, and was running a load test using artillery. When looking at the Phoenix dashboard I see the Ports going to 100% ...
New
pgiesin
This should be a simple problem but I just can’t seem to figure it out. I have a standalone Elixir app that won’t find the database. Dep...
New
ycv005
I have followed this StackOverflow post to install the specific version of Erlang. And When I am running mix ecto.setup then getting fol...
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
dokuzbir
Hello, I am trying to convert my lists to string without losing brackets.For start i have 3 map. They look like these buyer = %{ id: ...
New
qwerescape
Is there a way to get the call stack or stack trace at any point in the code? Not from exceptions, but an expression that returns how the...
New
LegitStack
I’m trying to make a websocket server in Phoenix or raw Elixir. I heard about gun, I think I could use cowboy, but since I’m not that sma...
New
Mooodi
Given a string, how can I get access to its character by index? Enum.at("my_string", 2) doesn't work. Or rather, not char, but a substr...
New

Other popular topics Top

lanycrost
Hi everyone! I need implement if…else if…else condition from my elixir code, and anymore of this control flow structures not work proper...
New
Harrisonl
We have an ECS cluster with 4 services, where each task joins a single cluster, via discovery ECS discovery service. Currently when I de...
New
jononomo
I am trying to figure out how Mix knows whether the environment is test, dev, or prod -- where is this set? Thanks.
New
yurko
Here are few pieces of (common) Linux knowledge that we use for reasonably small one server apps. We use Ubuntu but this should work for ...
New
jerry
Good day to you all. I have been struggling to get a query involving like and ilike to work. Can anyone assist me on this, please? pro...
New
itssasanka
Hi all, Trying to get some more clarity over utc_datetime and naive_datetime for Ecto: https://hexdocs.pm/ecto/Ecto.Schema.html#module-...
New
axelson
This post is a wiki (feel free to hit the edit button near the bottom right of this post to add your own changes!) This post collects co...
239 45766 226
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
vertexbuffer
Hello, can anybody help here..? I have a list of players and I what to delete an element, but every for loop the list is reverting to ori...
New
AstonJ
by Lance Halvorsen Elixir and Phoenix are generating tremendous excitement as an unbeatable platform for building modern web application...
460 27162 124
New

We're in Beta

About us Mission Statement