- Source Code:
A lightweight and simple utility that allows you to create images of different parts and positions from a Minecraft player's current skin texture. Useful for creating player skin previews, avatars, and profile pictures.
Basic useful feature list:
- Works with all skin types: 64x32, 64x64, slim, and legacy
- Applies skin "jacket" overlay where applicable while maintaining opacity
- Uses appropriate default skin ("Steve" or "Alex") when the player has no skin
- Convenient conversion of image to byte array and data URI
- Easily extensible to create different positions from skin parts
This utility must be used with my fork of the Mojang AccountsClient library (https://git.io/vMyBn).
This dependency is automatically included when compiling with Maven since it is defined in the POM definition and obtained from the repository at https://deadmandungeons.com/artifactory/public
Using AccountsClient, you can get current profile information on a player through the Mojang API. Either retrieve a player's Profile by username which includes their unique ID, or retrieve a player's MinecraftProfile by ID which also includes their skin and cape texture information.
All methods of MinecraftSkinUtil accept the MinecraftProfile for the player who's skin should be retrieved since it contains the texture information necessary to construct the images.
Using Maven, simply add the following repository and dependency to your project POM definition:
Get an image of a player's face that is 64x64 in size (or 8 times larger than original 1x1 pixel scale since player faces are 8x8 pixels):
Get an image of a player's front position:Code (Text):SkinImage face = MinecraftSkinUtil.getPlayerSkinPart(profile, SkinPart.HEAD_FRONT, 8);
Convert SkinImage result to other useful formats:Code (Text):SkinImage front = MinecraftSkinUtil.getPlayerSkinFront(profile, 8)
These examples in practice:Code (Text):BufferedImage image = front.getImage();
byte imageData = front.toByteArray();
String imageDataUri = front.toDataUri();
Code (Text):UUID id = UUID.fromString("fc346643-0f0c-4830-8534-c50dac0b331d");
MinecraftProfileRepository repository = new HttpProfileRepository();
MinecraftProfile profile = repository.findProfileById(id);
SkinImage face = MinecraftSkinUtil.getPlayerSkinPart(profile, SkinPart.HEAD_FRONT, 8);
String faceHtml = "<img src=\"" + face.toDataUri() + "\" />";
SkinImage front = MinecraftSkinUtil.getPlayerSkinFront(profile, 8);
String frontHtml = "<img src=\"" + front.toDataUri() + "\" />";
- Include player cape as a SkinPart
- Option to include player cape in skin positions
- Option to show player cape as when Elytra is equipped