GithubHelp home page GithubHelp logo

afkbrb / github-avatar-generator Goto Github PK

View Code? Open in Web Editor NEW
45.0 1.0 7.0 56 KB

:octocat: Generate github-style avatar with java awt

License: Apache License 2.0

Java 100.00%
github github-style avatar avatar-generator java awt

github-avatar-generator's Introduction

Github Avatar Generator

Generate github-style avatar with java awt.

This project was inspired by gabrie-allaigre/avatar-generator.

Result Set

Dependency

The artifact has been released to center maven, simply add dependency.

<dependency>
    <groupId>com.github.afkbrb</groupId>
    <artifactId>github-avatar-generator</artifactId>
    <version>1.0.0</version>
</dependency>

API

Configuration

Method Description Default
setPadding(int padding) Set the padding of the avatar. 32
setCellCount(int cellCount) Set the number of cells of the avatar. 5
setCellSize(int cellSize) Set the size of each cell, both length and height of each cell will be set to it. 64
setForeColor(Color color) Set the foreground color of the avatar. random
setForeColors(Color... colors) Set the foreground color set, the final foreground color will be chosen at random in it. random
setForeColors(List colors) Set the foreground color set, the final foreground color will be chosen at random in it. random
setTransparent(boolean transparent) Set the transparency of the avatar. false
setBackColor(Color color) Set the background color of the avatar. Color(241, 241, 241)

Notice

The final foreground color will be decided by the last called setForeColor* method. And if none of these setForeColor* methods are called, the foreground color will be generated at random but will also meet certain conditions to make the color look nice.

Creation

Method Description
void build() Build the avatar, calling the method each time will create a new avatar image at random according to configuration.
BufferedImage generateAndGetAvatar() Generate a new avatar image and return it.
void showAvatar() Show the generated avatar image with local application.
void saveAsPNG(String filepath) Save avatar image as PNG file. The filepath include path and filename, for example, "E:/avatar.png", you should make sure that the path exists.

Example

Default

Avatar avatar = new Avatar();
avatar.showAvatar();

Save

Avatar avatar = new Avatar();
avatar.saveAsPNG("E:/avatar.png");

Set padding and cell size

AvatarConfig config = new AvatarConfig();
config.setPadding(16);
config.setCellSize(32);
Avatar avatar = new Avatar(config);
avatar.showAvatar();

Set the number of cells per row / column

config.setCellCount(8);

Set transparency

config.setTransparent(true);

Set color

config.setForeColor(Color.MAGENTA);
// config.setBackColor(Color.LIGHT_GRAY);

Set colors

config.setForeColors(Color.MAGENTA, Color.BLUE, Color.GREEN);

// the other way
List<Color> colors = new ArrayList<>();
colors.add(Color.YELLOW);
colors.add(Color.ORANGE);
colors.add(Color.CYAN);
config.setForeColors(colors);

For more example details, see example.

Licence

The Apache Software License, Version 2.0

github-avatar-generator's People

Contributors

afkbrb avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.