Commit 6ccf6c31 authored by Drahomír Karchňák's avatar Drahomír Karchňák

Testing new way to draw image with results.

parent 400aa872
......@@ -302,19 +302,9 @@ def getVersionNameFromGit() {
}
def branchName = getBranchNameFromGit()
return stdoutVersion.toString().trim() + '-' + branchName
}
def getVersionCodeFromGit() {
def stdout = new ByteArrayOutputStream()
exec {
commandLine 'git', 'rev-list', 'HEAD', '--count'
standardOutput = stdout
}
return stdout.toString().trim().toInteger()
}
def getBranchNameFromGit() {
def stdout = new ByteArrayOutputStream()
exec {
......@@ -325,6 +315,16 @@ def getBranchNameFromGit() {
return branchString.contains("/") ? branchString.substring(branchString.lastIndexOf("/") + 1) : branchString
}
def getVersionCodeFromGit() {
def stdout = new ByteArrayOutputStream()
exec {
commandLine 'git', 'rev-list', 'HEAD', '--count'
standardOutput = stdout
}
return stdout.toString().trim().toInteger()
}
task wrapper(type: Wrapper) {
gradleVersion = '2.4'
}
......@@ -17,12 +17,15 @@ package at.alladin.rmbt.statisticServer.export;
import java.awt.Color;
import java.awt.Font;
import java.awt.FontFormatException;
import java.awt.FontMetrics;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.GraphicsEnvironment;
import java.awt.RenderingHints;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
......@@ -195,78 +198,95 @@ public class ImageExport extends ServerResource {
return buf.toString();
}
protected void drawCenteredString(String s, int x, int y, int w, int h, Graphics g) {
protected void drawCenteredString(String s, int x, int y, int w, int h, Graphics g) {
FontMetrics fm = g.getFontMetrics();
x += (w - fm.stringWidth(s)) / 2;
y += (fm.getAscent() + (h - (fm.getAscent() + fm.getDescent())) / 2);
g.drawString(s, x, y);
}
}
}
public class ForumBannerGenerator extends ShareImageGenerator {
private static final int BANNER_WIDTH = 560;
private static final int BANNER_HEIGHT = 300;
@Override
public BufferedImage generateImage(String lang, double upload, double download, double ping, String isp, String typ, String signal, String os) throws IOException{
String unknownString = "";
if (lang.equals("cs")) {
unknownString = "neznámé";
} else if (lang.equals("de")) {
unknownString = "unbekannt";
} else {
unknownString = "unknown";
}
BufferedImage img = new BufferedImage(600, 200, BufferedImage.TYPE_INT_ARGB);
img.createGraphics();
Graphics2D g = (Graphics2D)img.getGraphics();
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
private static final String ROBOTO_LIGHT_FILE = "fonts/Roboto-Light.ttf";
private static final String ROBOTO_MEDIUM_FILE = "fonts/Roboto-Medium.ttf";
BufferedImage img2 = ImageIO.read(getClass().getResourceAsStream("forumbanner_" + lang + ".png"));
g.drawImage(img2, null, 0, 0);
private static final String FORUM_BANNER_IMAGE = "forumbanner_en.png";
//Speeds
g.setColor(Color.black);
g.setFont(new Font("Droid Sans", Font.BOLD, 60));
g.drawString(formatNumber(download, lang), 30, 105);
g.drawString(formatNumber(upload, lang), 230, 105);
g.drawString(formatNumber(ping, lang), 440, 105);
@Override
public BufferedImage generateImage(String lang, double upload, double download, double ping, String isp, String typ, String signal, String os) throws IOException{
BufferedImage finalImage = new BufferedImage(BANNER_WIDTH, BANNER_HEIGHT, BufferedImage.TYPE_INT_RGB);
Graphics2D finalImageGraphics = finalImage.createGraphics();
finalImageGraphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
//ISP and other information
g.setColor(Color.WHITE);
g.setFont(new Font("Verdana", Font.BOLD,16));
InputStream robotoLightInputStream = getClass().getResourceAsStream(ROBOTO_LIGHT_FILE);
//cs
if (lang.equals("cs")) {
//left
g.drawString((typ == null)?unknownString:typ, 110, 168);
g.drawString((isp == null)?unknownString:isp, 110, 191);
// right
g.drawString((signal==null)?unknownString:signal + " dBm", 400, 168);
g.drawString((os==null)?unknownString:os, 400, 191);
Font robotoLight;
try {
robotoLight = Font.createFont(Font.TRUETYPE_FONT, robotoLightInputStream);
} catch (FontFormatException e) {
e.printStackTrace();
robotoLight = new Font("Droid Sans", Font.BOLD, 60);
}
else if (lang.equals("de")) { //de
//left
g.drawString((typ == null)?unknownString:typ, 110, 168);
g.drawString((isp == null)?unknownString:isp, 110, 191);
//right
g.drawString((signal==null)?unknownString:signal + " dBm", 410, 168);
g.drawString((os==null)?unknownString:os, 410, 191);
}
else { //en
//left
g.drawString((typ == null)?unknownString:typ, 130, 168);
g.drawString((isp == null)?unknownString:isp, 90, 191);
//right
g.drawString((signal==null)?unknownString:signal + " dBm", 445, 168);
g.drawString((os==null)?unknownString:os, 445, 191);
}
return img;
GraphicsEnvironment.getLocalGraphicsEnvironment().registerFont(robotoLight);
BufferedImage backgroundImage = ImageIO.read(getClass().getResourceAsStream(FORUM_BANNER_IMAGE));
finalImageGraphics.drawImage(backgroundImage, null, 0, 0);
finalImageGraphics.setFont(robotoLight);
finalImageGraphics.setColor(Color.BLACK);
finalImageGraphics.drawString("Testing", 30, 30);
return finalImage;
// BufferedImage img2 = ImageIO.read(getClass().getResourceAsStream("forumbanner_" + lang + ".png"));
// g.drawImage(img2, null, 0, 0);
//
// //Speeds
// g.setColor(Color.black);
// g.setFont(new Font("Droid Sans", Font.BOLD, 60));
// g.drawString(formatNumber(download, lang), 30, 105);
// g.drawString(formatNumber(upload, lang), 230, 105);
// g.drawString(formatNumber(ping, lang), 440, 105);
//
//
// //ISP and other information
// g.setColor(Color.WHITE);
// g.setFont(new Font("Verdana", Font.BOLD,16));
//
// //cs
// if (lang.equals("cs")) {
// //left
// g.drawString((typ == null)?unknownString:typ, 110, 168);
// g.drawString((isp == null)?unknownString:isp, 110, 191);
//
// // right
// g.drawString((signal==null)?unknownString:signal + " dBm", 400, 168);
// g.drawString((os==null)?unknownString:os, 400, 191);
// }
// else if (lang.equals("de")) { //de
// //left
// g.drawString((typ == null)?unknownString:typ, 110, 168);
// g.drawString((isp == null)?unknownString:isp, 110, 191);
//
// //right
// g.drawString((signal==null)?unknownString:signal + " dBm", 410, 168);
// g.drawString((os==null)?unknownString:os, 410, 191);
// }
// else { //en
// //left
// g.drawString((typ == null)?unknownString:typ, 130, 168);
// g.drawString((isp == null)?unknownString:isp, 90, 191);
//
// //right
// g.drawString((signal==null)?unknownString:signal + " dBm", 445, 168);
// g.drawString((os==null)?unknownString:os, 445, 191);
// }
//
// return img;
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment