-
Notifications
You must be signed in to change notification settings - Fork 6
/
DiscordStyleIcon.java
83 lines (73 loc) · 2.56 KB
/
DiscordStyleIcon.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import java.awt.*;
import java.awt.geom.Rectangle2D;
import java.awt.image.BufferedImage;
import java.io.*;
import java.util.Random;
import javax.imageio.ImageIO;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
public class DiscordStyleIcon
{
//Initialize a random number generator
public static final Random r = new Random();
//Image Size
public static final double width = 64, height = 64;
public static void main(String[] args) throws Exception
{
if(args.length != 1)
{
System.out.println("You can only use a one-word server name...!");
}
String s = args[0];
//Create the image
BufferedImage bi = new BufferedImage((int) width,
(int) height,
BufferedImage.TYPE_INT_ARGB
);
//Initialize Graphics2D for drawing on the image
Graphics2D g = bi.createGraphics();
//Some renderer hints that make the output image sharper
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
g.setRenderingHint(RenderingHints.KEY_COLOR_RENDERING,
RenderingHints.VALUE_COLOR_RENDER_QUALITY);
g.setRenderingHint(RenderingHints.KEY_RENDERING,
RenderingHints.VALUE_RENDER_QUALITY);
g.setPaint(Color.DARK_GRAY);
g.fillOval(0, 0, (int) width, (int) height);
g.setFont(new Font("Consolas", Font.PLAIN, 32));
Rectangle2D r2d = g.getFontMetrics().getStringBounds(s, g);
g.setPaint(Color.WHITE);
float xPos = (float) ((width - r2d.getWidth()) / 2);
float yPos = (float) (height + r2d.getHeight() / 2) / 2;
g.drawString(s, xPos, yPos);
/*for(int i = 0; i < width; i++)
{
for(int j = 0; j < height; j++)
{
}
}*/
System.out.println("Writing...");
ImageIO.write(bi, "png", new File("server-icon.png"));
System.out.println("Done!");
if(GraphicsEnvironment.isHeadless())
{
return;
}
//Display image
JFrame f = new JFrame();
f.getContentPane().setLayout(new FlowLayout());
f.getContentPane().add(new JLabel(new ImageIcon(bi)));
f.pack();
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setVisible(true);
}
public static int RGBTransform(int R, int G, int B)
{
R = (R << 16) & 0x00FF0000;
G = (G << 8) & 0x0000FF00;
B = B & 0x000000FF;
return 0xFF000000 | R | G | B;
}
}