Skip to content
This repository has been archived by the owner on Nov 18, 2022. It is now read-only.

Commit

Permalink
Fix proportions, add rotation anchors, basically fix #25
Browse files Browse the repository at this point in the history
Also fix #24
Oh, and #20, for real this time
  • Loading branch information
unascribed committed Jul 10, 2017
1 parent 3cbea59 commit dfedfa2
Show file tree
Hide file tree
Showing 12 changed files with 499 additions and 238 deletions.
55 changes: 49 additions & 6 deletions src/main/java/com/surgeplay/visage/distributor/VisageHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@

package com.surgeplay.visage.distributor;

import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.awt.image.BufferedImage;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.DataInputStream;
Expand Down Expand Up @@ -204,7 +209,11 @@ public void handle(String target, Request baseRequest, HttpServletRequest reques
}
int rounded = Math.round(height / (float) granularity)*granularity;
if (rounded != height) {
sendPermanentRedirect(baseUrl+"/"+modeStr+"/"+rounded+"/"+subject, response);
String query = "";
if (request.getQueryString() != null) {
query = "?"+request.getQueryString();
}
sendPermanentRedirect(baseUrl+"/"+modeStr+"/"+rounded+"/"+subject+query, response);
return;
}

Expand Down Expand Up @@ -258,7 +267,11 @@ public void onProfileLookupFailed(GameProfile profile, Exception e) {
return;
} else if (result[0] instanceof UUID) {
uuid = (UUID) result[0];
response.sendRedirect(baseUrl+"/"+modeStr+"/"+height+"/"+uuid.toString().replace("-", ""));
String query = "";
if (request.getQueryString() != null) {
query = "&"+request.getQueryString();
}
response.sendRedirect(baseUrl+"/"+modeStr+"/"+height+"/"+uuid.toString().replace("-", "")+"?resolvedUsername"+query);
j.set(subject, uuid.toString());
j.pexpire(subject, resolverTtlMillis);
return;
Expand Down Expand Up @@ -305,7 +318,6 @@ public void onProfileLookupFailed(GameProfile profile, Exception e) {
sj.pexpire(uuid.toString()+":profile", skinTtlMillis);
}
}
System.out.println(profile);
if (skinResp != null && skinResp.length > 3) {
skin = skinResp;
} else {
Expand Down Expand Up @@ -352,8 +364,6 @@ public void onProfileLookupFailed(GameProfile profile, Exception e) {
}
}

System.out.println(profile);

if (mode == RenderMode.SKIN) {
write(response, missed, skin, "none");
return;
Expand All @@ -373,7 +383,40 @@ public void onProfileLookupFailed(GameProfile profile, Exception e) {
if (resp == null) {
continue;
}
write(response, missed, resp.png, resp.renderer);
byte[] png = resp.png;
if (request.getParameter("resolvedUsername") != null) {
BufferedImage img = ImageIO.read(new ByteArrayInputStream(png));
Graphics2D g = img.createGraphics();
g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
g.setColor(Color.RED);
g.fillRect(0, 0, img.getWidth(), 8);
g.fillRect(0, 0, 8, img.getHeight());
g.fillRect(img.getWidth()-8, 0, 8, img.getHeight());
g.fillRect(0, img.getHeight()-8, img.getWidth(), 8);
if (img.getWidth() >= 480) {
g.setFont(Font.decode("Dialog-Bold").deriveFont(48f));
g.drawString("USERNAME RENDER", 12, 56);
} else if (img.getWidth() >= 256) {
g.setFont(Font.decode("Dialog-Bold").deriveFont(24f));
g.drawString("USERNAME RENDER", 12, 32);
} else if (img.getWidth() >= 144) {
g.setFont(Font.decode("Dialog-Bold").deriveFont(12f));
g.drawString("USERNAME RENDER", 12, 24);
} else if (img.getWidth() >= 96) {
g.setFont(Font.decode("Dialog-Bold").deriveFont(12f));
g.drawString("USERNAME", 12, 24);
g.drawString("RENDER", 12, 38);
} else if (img.getWidth() >= 64) {
g.setFont(Font.decode("Dialog").deriveFont(8f));
g.drawString("USERNAME", 10, 18);
g.drawString("RENDER", 10, 26);
}
g.dispose();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ImageIO.write(img, "PNG", baos);
png = baos.toByteArray();
}
write(response, missed, png, resp.renderer);
return;
}
if (ex != null) {
Expand Down
Loading

0 comments on commit dfedfa2

Please sign in to comment.