Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@ log
logs
_build

doc/specs/
doc/src/egd.xml
doc/src/egd_ug.xml
doc/src/ref_man.xml
/doc/

.rebar3
_*
Expand Down
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Change log

## Version 0.10.1 (February 09, 2025)

- Align to OTP 24: use `erlang:crc32/1` instead of `zlib:crc32/2`, as the later
one has been deprecated in OTP 24 and was removed in OTP 27.
- Convert documentation from `erl_docgen` style XML files to `ex_doc` style
Markdown files.

## Previous versions

- 0.10.0: Add `egd_font:load_binary/1`
- 0.9.1: Reinstate `priv_dir` with fonts
- 0.9.0: Initial commit or [erlang/egd](https://github.com/erlang/egd)
132 changes: 125 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,128 @@
Erlang Graphical Drawer
=====
# Erlang Graphical Drawer

Erlang Graphical Drawer is an interface for 2d-image rendering and is used by Percept to generate dynamic graphs to its web
pages. All code is pure erlang, no drivers needed.
Erlang Graphical Drawer ([egd](https://github.com/erlang/egd)) is an interface
for 2d-image rendering and is used by
[Percept](https://github.com/erlang/percept) to generate dynamic graphs to
its web pages. All code is pure Erlang, no drivers needed.

Build
-----
The library is intended for small to medium image sizes with low complexity for
optimal performance. The library handles horizontal lines better then vertical
lines.

$ rebar3 compile
The foremost purpose for this module is to enable users to generate images from
Erlang code and/or datasets and to send these images to either files or web
servers.

## File example

Drawing examples:

```erlang
-module(img).

-export([do/0]).

do() ->
Im = egd:create(200,200),
Red = egd:color({255,0,0}),
Green = egd:color({0,255,0}),
Blue = egd:color({0,0,255}),
Black = egd:color({0,0,0}),
Yellow = egd:color({255,255,0}),

% Line and fillRectangle

egd:filledRectangle(Im, {20,20}, {180,180}, Red),
egd:line(Im, {0,0}, {200,200}, Black),

egd:save(egd:render(Im, png), "test1.png"),

egd:filledEllipse(Im, {45, 60}, {55, 70}, Yellow),
egd:filledEllipse(Im, {145, 60}, {155, 70}, Blue),

egd:save(egd:render(Im, png), "test2.png"),

R = 80,
X0 = 99,
Y0 = 99,

Pts = [ {X0 + trunc(R*math:cos(A*math:pi()*2/360)),
Y0 + trunc(R*math:sin(A*math:pi()*2/360))
} || A <- lists:seq(0,359,5)],
lists:map(
fun({X,Y}) ->
egd:rectangle(Im, {X-5, Y-5}, {X+5,Y+5}, Green)
end, Pts),

egd:save(egd:render(Im, png), "test3.png"),

% Text
Filename = filename:join([code:priv_dir(egd), "fonts", "6x11_latin1.wingsfont"]),
Font = egd_font:load(Filename),
{W,H} = egd_font:size(Font),
String = "egd says hello",
Length = length(String),

egd:text(Im, {round(100 - W*Length/2), 200 - H - 5}, Font, String, Black),

egd:save(egd:render(Im, png), "test4.png"),

egd:destroy(Im).
```

First save:

![test1.png](assets/test1.gif)

Second save:

![test2.png](assets/test2.gif)

Third save:

![test3.png](assets/test3.gif)

Fourth save:

![test4.png](assets/test4.gif)

## ESI example

Using `egd` with [inets](https://www.erlang.org/doc/apps/inets/) ESI to generate
images on the fly:

```erlang
-module(img_esi).

-export([image/3]).

image(SessionID, _Env, _Input) ->
mod_esi:deliver(SessionID, header()),
Binary = my_image(),
mod_esi:deliver(SessionID, binary_to_list(Binary)).

my_image() ->
Im = egd:create(300,20),
Black = egd:color({0,0,0}),
Red = egd:color({255,0,0}),
egd:filledRectangle(Im, {30,14}, {270,19}, Red),
egd:rectangle(Im, {30,14}, {270,19}, Black),

Filename = filename:join([code:priv_dir(egd), "fonts", "6x11_latin1.wingsfont"]),
Font = egd_font:load(Filename),
egd:text(Im, {30, 0}, Font, "egd with esi callback", Black),
Bin = egd:render(Im, png),
egd:destroy(Im),
Bin.

header() ->
"Content-Type: image/png\r\n\r\n".
```

Result:

![Example of result](assets/img_esi_result.gif)

For more information regarding ESI, please see
[inets](https://www.erlang.org/doc/apps/inets/) application
[mod_esi](https://www.erlang.org/doc/apps/inets/mod_esi.html#).
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
52 changes: 0 additions & 52 deletions doc/src/book.xml

This file was deleted.

90 changes: 0 additions & 90 deletions doc/src/egd_ug.xmlsrc

This file was deleted.

50 changes: 0 additions & 50 deletions doc/src/img.erl

This file was deleted.

25 changes: 0 additions & 25 deletions doc/src/img_esi.erl

This file was deleted.

Loading