Nginx module to generate gmail-like avatars based on user initials.
Module requires libcairo:
sudo apt-get install libcairo2 libcairo2-dev
To install module you should compile nginx with it:
cd nginx-1.11.3/
./configure --add-module=/path/to/module/avatars_gen
make && sudo make install
Module could be enabled on location context:
http {
server {
listen 80;
server_name localhost;
# Default params
location /avatar {
avatars_gen;
}
# Black & white avatar
location /bw-avatar {
avatars_gen;
avatars_gen_bg_color FFFFFF;
avatars_gen_contour_color 000000;
avatars_gen_font_color 000000;
avatars_gen_font_face serif;
}
# Custom size and without contour
location /big-contourless {
avatars_gen;
avatars_gen_size 400;
avatars_gen_show_contour off;
}
# Customized font
location /font {
avatars_gen;
avatars_gen_size 300;
avatars_gen_font_size 100;
avatars_gen_font_face "Liberation Sans Narrow";
avatars_gen_font_bold on;
}
# Square form
location /square {
avatars_gen;
avatars_gen_square on;
avatars_gen_bg_color 72A3F1;
avatars_gen_contour_color E9AD00;
avatars_gen_font_color 9BFAB5;
avatars_gen_size 100;
avatars_gen_font_face "Liberation Sans";
avatars_gen_show_contour off;
}
}
}
Directives:
avatars_gen
- enables avatars generation on this locationavatars_gen_bg_color
(default:4285f5
) - background color of avataravatars_gen_contour_color
(default:333333
) - circle contour coloravatars_gen_font_color
(default:FFFFFF
) - font coloravatars_gen_font_face
(default:sans
) - font-face nameavatars_gen_font_size
(default:avatars_gen_size / 2
) - font size in pixelsavatars_gen_size
(default:100
) - avatar size in pixelsavatars_gen_show_contour
(default:on
) - show/hide contouravatars_gen_font_italic
(default:off
) - italic font on/offavatars_gen_font_bold
(default:off
) - bold font on/offavatars_gen_square
(default:off
) - square avatars on/off
You could change avatar colors with GET args (i.e. ?bg_color=FFFFFF&font_color=000000
):
bg_color
contour_color
font_color
You can make request to http://localhost/avatar/GH
and it will generate 100x100 png image on-the-go:
Default:
Black & white:
Custom size and without contour:
Customized font:
Square form:
Module currently supports only 1 and 2 symbols initials.
- fix HEAD method
- default settings
- unicode initials
- avatars size configuration
- enable/disable border
- rich font settings
- square avatars
- colors configuration through GET parameters
- random colors mode
- different formats (jpg/svg)
- configurations merge
The MIT License (MIT)
Copyright (c) 2016 Yuri Shikanov